Only shown relevant type params in E0283 label

When we point at a binding to suggest giving it a type, erase all the
type for ADTs that have been resolved, leaving only the ones that could
not be inferred. For small shallow types this is not a problem, but for
big nested types with lots of params, this can otherwise cause a lot of
unnecessary visual output.
This commit is contained in:
Esteban Kuber 2021-11-08 19:15:54 +00:00
parent 0fb1c371d4
commit 78e88f46d6
5 changed files with 136 additions and 3 deletions

View file

@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `Foo<{_: u32}>`
LL | let foo = Foo::foo();
| --- ^^^^^^^^ cannot infer the value of const parameter `N`
| |
| consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified
| consider giving `foo` the explicit type `Foo<{_: _}>`, where the type parameter `N` is specified
error: aborting due to previous error

View file

@ -0,0 +1,13 @@
fn main() {
let foo = new(1, ""); //~ ERROR E0283
}
struct Bar<T, K, N: Default> {
t: T,
k: K,
n: N,
}
fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
Bar { t, k, n: Default::default() }
}

View file

@ -0,0 +1,22 @@
error[E0283]: type annotations needed for `Bar<i32, &str, Z>`
--> $DIR/erase-type-params-in-label.rs:2:15
|
LL | let foo = new(1, "");
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `new`
| |
| consider giving `foo` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified
|
= note: cannot satisfy `_: Default`
note: required by a bound in `new`
--> $DIR/erase-type-params-in-label.rs:11:17
|
LL | fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
| ^^^^^^^ required by this bound in `new`
help: consider specifying the type arguments in the function call
|
LL | let foo = new::<T, K, Z>(1, "");
| +++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0283`.

View file

@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `[usize; _]`
LL | let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
| - ^^^ cannot infer the value of const parameter `N` declared on the function `foo`
| |
| consider giving this pattern the explicit type `[usize; _]`, where the type parameter `N` is specified
| consider giving this pattern the explicit type `[_; _]`, where the type parameter `N` is specified
error: aborting due to previous error