Skip to content

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

Closed
@BoxyUwU

Description

@BoxyUwU

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

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions