diff options
| author | bors <bors@rust-lang.org> | 2021-05-13 08:08:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-13 08:08:20 +0000 |
| commit | 703f2e1685a63c9718bcc3b09eb33a24334a7541 (patch) | |
| tree | dfb1e19f4dee3445caeb1936022fc56eb14d0105 /compiler/rustc_codegen_llvm | |
| parent | 72d07257ed46c70bcaf719e15882af539d0a5155 (diff) | |
| parent | 4c72efc8167405ca1cc3002266a9bf15f70dafb3 (diff) | |
| download | rust-703f2e1685a63c9718bcc3b09eb33a24334a7541.tar.gz rust-703f2e1685a63c9718bcc3b09eb33a24334a7541.zip | |
Auto merge of #85041 - mibac138:suggest-generics, r=estebank
Suggest adding a type parameter for impls
Add a new suggestion upon encountering an unknown type in a `impl` that suggests adding a new type parameter. This diagnostic suggests to add a new type parameter even though it may be a const parameter, however after adding the parameter and running rustc again a follow up error steers the user to change the type parameter to a const parameter.
```rust
struct X<const C: ()>();
impl X<C> {}
```
suggests
```
error[E0412]: cannot find type `C` in this scope
--> bar.rs:2:8
|
1 | struct X<const C: ()>();
| ------------------------ similarly named struct `X` defined here
2 | impl X<C> {}
| ^
|
help: a struct with a similar name exists
|
2 | impl X<X> {}
| ^
help: you might be missing a type parameter
|
2 | impl<C> X<C> {}
| ^^^
```
After adding a type parameter the code now becomes
```rust
struct X<const C: ()>();
impl<C> X<C> {}
```
and the error now fully steers the user towards the correct code
```
error[E0747]: type provided when a constant was expected
--> bar.rs:2:11
|
2 | impl<C> X<C> {}
| ^
|
help: consider changing this type parameter to be a `const` generic
|
2 | impl<const C: ()> X<C> {}
| ^^^^^^^^^^^
```
r? `@estebank`
Somewhat related #84946
Diffstat (limited to 'compiler/rustc_codegen_llvm')
0 files changed, 0 insertions, 0 deletions
