diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2021-11-08 19:15:54 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2021-12-07 02:05:34 +0000 |
| commit | 78e88f46d60c5487946fc7632a7561bdff6b9fcc (patch) | |
| tree | 44b9100cdf3f2468ec60299b3adebc9ce16d3d55 /src/test | |
| parent | 0fb1c371d4a14f9ce7a721d8aea683a6e6774f6c (diff) | |
| download | rust-78e88f46d60c5487946fc7632a7561bdff6b9fcc.tar.gz rust-78e88f46d60c5487946fc7632a7561bdff6b9fcc.zip | |
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.
Diffstat (limited to 'src/test')
4 files changed, 37 insertions, 2 deletions
diff --git a/src/test/ui/const-generics/defaults/doesnt_infer.stderr b/src/test/ui/const-generics/defaults/doesnt_infer.stderr index b57975e26f2..183be1b1517 100644 --- a/src/test/ui/const-generics/defaults/doesnt_infer.stderr +++ b/src/test/ui/const-generics/defaults/doesnt_infer.stderr @@ -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 diff --git a/src/test/ui/inference/erase-type-params-in-label.rs b/src/test/ui/inference/erase-type-params-in-label.rs new file mode 100644 index 00000000000..4a163d0b810 --- /dev/null +++ b/src/test/ui/inference/erase-type-params-in-label.rs @@ -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() } +} diff --git a/src/test/ui/inference/erase-type-params-in-label.stderr b/src/test/ui/inference/erase-type-params-in-label.stderr new file mode 100644 index 00000000000..b665fade9d8 --- /dev/null +++ b/src/test/ui/inference/erase-type-params-in-label.stderr @@ -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`. diff --git a/src/test/ui/inference/issue-83606.stderr b/src/test/ui/inference/issue-83606.stderr index 65f3336b935..c66606b9c83 100644 --- a/src/test/ui/inference/issue-83606.stderr +++ b/src/test/ui/inference/issue-83606.stderr @@ -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 |
