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

Wrong suggestion for const generic type #89013

Closed
CGMossa opened this issue Sep 16, 2021 · 1 comment · Fixed by #89029
Closed

Wrong suggestion for const generic type #89013

CGMossa opened this issue Sep 16, 2021 · 1 comment · Fixed by #89029
Assignees
Labels
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

@CGMossa
Copy link

CGMossa commented Sep 16, 2021

Given the following code: (see play.rust-lang.org link).

trait Foo<const N: usize> {
    fn do_x(&self) -> [u8; N];
}

struct Bar;

impl Foo<N = const 3> for Bar {
    fn do_x(&self) -> [u8; N] {
        [0u8; N]
    }
}

The current output is:

Compiling playground v0.0.1 (/playground)
error: missing type to the right of `=`
 --> src/lib.rs:7:13
  |
7 | impl Foo<N = const 3> for Bar {
  |             ^
  |
help: to constrain the associated type, add a type after `=`
  |
7 | impl Foo<N = TheTypeconst 3> for Bar {
  |              +++++++
help: remove the `=` if `N` is a type
  |
7 - impl Foo<N = const 3> for Bar {
7 + impl Foo<N const 3> for Bar {
  | 

error: expected one of `,`, `>`, a const expression, lifetime, or type, found keyword `const`
 --> src/lib.rs:7:14
  |
7 | impl Foo<N = const 3> for Bar {
  |              ^^^^^ expected one of `,`, `>`, a const expression, lifetime, or type

error: could not compile `playground` due to 2 previous errors

Notice the TheTypeconst in the above error message.

I've checked if this is the case on nightly, and at the time of this filing, this
is also an issue on nightly.

@CGMossa CGMossa 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 Sep 16, 2021
@notriddle
Copy link
Contributor

@rustbot claim

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Oct 1, 2021
…estebank

feat(rustc_parse): recover from pre-RFC-2000 const generics syntax

Fixes rust-lang#89013
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 1, 2021
…estebank

feat(rustc_parse): recover from pre-RFC-2000 const generics syntax

Fixes rust-lang#89013
@bors bors closed this as completed in d8e9db0 Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants