Repository: rust
Issue: Compiler error messages leads to wrong usage of const generics
Labels: A-diagnostics,T-compiler,C-bug,A-const-generics,D-invalid-suggestion,D-incorrect

Hi, folks!

Misusing const generics generates errors messages that lead the user to a wrong usage of the feature, let's follow an example:

Given this very simple (and wrong) definition:

[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3080fe14eed09a41f8bdc8381a6da361)

```rust
struct Foo<const AHA: usize>{}

impl Foo {}
```

The compiler generates this error message:

```rust
error[E0107]: missing generics for struct `Foo`
 --> src/lib.rs:3:6
  |
3 | impl Foo {}
  |      ^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `AHA`
 --> src/lib.rs:1:8
  |
1 | struct Foo<const AHA: usize>{}
  |        ^^^       ---
help: add missing generic argument
  |
3 | impl Foo<AHA> {}
  |      ~~~~~~~~
```

Following the compiler suggestion:

```rust
struct Foo<const AHA: usize>{}

impl Foo<AHA> {}
```

We have a new error:

```rust
error[E0412]: cannot find type `AHA` in this scope
 --> src/lib.rs:3:10
  |
3 | impl Foo<AHA> {}
  |     -    ^^^ not found in this scope
  |     |
  |     help: you might be missing a type parameter: `<AHA>`

error[E0747]: unresolved item provided when a constant was expected
 --> src/lib.rs:3:10
  |
3 | impl Foo<AHA> {}
  |          ^^^
  |
help: if this generic argument was intended as a const parameter, surround it with braces
  |
3 | impl Foo<{ AHA }> {}
  |          +     +
```

Applying the suggestion:

```rust
struct Foo<const AHA: usize>{}

impl Foo<{ AHA }> {}
```

Leads to a new error:

```rust
error[E0425]: cannot find value `AHA` in this scope
 --> src/lib.rs:3:12
  |
3 | impl Foo<{ AHA }> {}
  |     -      ^^^ not found in this scope
  |     |
  |     help: you might be missing a type parameter: `<AHA>`
```

And applying again:

```rust
struct Foo<const AHA: usize>{}

impl<AHA> Foo<{ AHA }> {}
```

Leads the user to a not intuitive point:

```rust
error[E0423]: expected value, found type parameter `AHA`
 --> src/lib.rs:3:17
  |
3 | impl<AHA> Foo<{ AHA }> {}
  |                 ^^^ not a value

error[E0207]: the type parameter `AHA` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:3:6
  |
3 | impl<AHA> Foo<{ AHA }> {}
  |      ^^^ unconstrained type parameter

```

---

Ideally, we should not guide the user to such a long and erroneous path, and give them the correct answer that may look like this: 
```rust
error[E???]: missing const generics for struct `Foo`
 --> src/lib.rs:3:6
  |
3 | impl Foo {}
  |      ^^^ expected 1 const generic argument
  |
note: struct defined here, with 1 const generic parameter: `AHA`
 --> src/lib.rs:1:8
  |
1 | struct Foo<const AHA: usize>{}
  |        ^^^       ---
help: add missing generic argument
  |
3 | impl<const AHA: usize> Foo<AHA> {}
  |      ~~~~~~~~
```

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"matheus-consoli"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->