Skip to content

Wrong diagnostic when incorrectly using const generics in impl block #79598

Closed
@rylev

Description

@rylev

The following incorrect code produces an incorrect diagnostic

#![feature(min_const_generics)]

struct Foo<const SET: bool>;

impl Foo<const SET: bool> {
    fn set_bar() -> Foo<true> {
        Foo
    }
}

The diagnostic produced is:

error: expected one of `>`, const, lifetime, or type, found keyword `const`
 --> src/lib.rs:5:10
  |
5 | impl Foo<const SET: bool> {
  |          ^^^^^ expected one of `>`, const, lifetime, or type

Confusingly const is shown as one of the expected items to replace const.

Of course, the user most likely meant to type:

impl <const SET: bool> Foo<SET> {

Here's a playground reproducing the issue for convenience: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=27ae1b8286d97da1df8240f84062a339

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions