Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad diagnostics when using associated const on type without turbofish #82566

Closed
BoxyUwU opened this issue Feb 26, 2021 · 4 comments · Fixed by #82579
Closed

Bad diagnostics when using associated const on type without turbofish #82566

BoxyUwU opened this issue Feb 26, 2021 · 4 comments · Fixed by #82579
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 26, 2021

Given the following code: here

struct Add<const N1: usize, const N2: usize>;
impl<const N1: usize, const N2: usize> Foo<N1, N2> {
    const SUM: usize = N1 + N2;
}
fn foo() -> [(); Add<10, 12>::SUM] {
    todo!()
}

The current output is:

error: expected one of `.`, `?`, `]`, or an operator, found `,`
 --> src/lib.rs:5:24
  |
5 | fn foo() -> [(); Add<10, 12>::SUM] {
  |                        ^ expected one of `.`, `?`, `]`, or an operator

error: aborting due to previous error

error: could not compile `playground`

Ideally the output should mention that the user needs to use a turbofish here:
Add::<10, 12>::SUM

cc @lcnr

@BoxyUwU BoxyUwU added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 26, 2021
@lcnr lcnr added the A-const-generics Area: const generics (parameters and arguments) label Feb 26, 2021
@lcnr
Copy link
Contributor

lcnr commented Feb 26, 2021

the help message seems to only be missing if there are 2 const arguments:

struct Foo<const N: usize, const M: usize>;
impl Foo<3, 4> {
    const SUM: () = ();
}

fn main() {
    Foo<3, 4>::SUM
}

using type parameters or just one const param causes a useful help message

struct Foo<const N: usize>;
impl Foo<3> {
    const SUM: () = ();
}

fn main() {
    Foo<3>::SUM
}

@osa1
Copy link
Contributor

osa1 commented Feb 27, 2021

@rustbot claim

@osa1
Copy link
Contributor

osa1 commented Feb 27, 2021

It turns out @lcnr 's repro is different than the original repro. My PR fixes @lcnr 's examples but not the original one. I'll update it to fix the original one too.

@osa1
Copy link
Contributor

osa1 commented Feb 27, 2021

All fixed.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 2, 2021
Fix turbofish recovery with multiple generic args

This consists of two commits, each can be individually reviewed.

- First commit fixes the issue in [this comment](rust-lang#82566 (comment)).
- Second commit fixes rust-lang#82566

---

r? ````@estebank````
@bors bors closed this as completed in 992b914 Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants