Skip to content

Commit e420f44

Browse files
committed
Account for cases where we can find the type arg name, but the local name is _
1 parent 9616b33 commit e420f44

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
152152
// | the type parameter `E` is specified
153153
// ```
154154
let (ty_msg, suffix) = match &local_visitor.found_ty {
155+
Some(ty) if &ty.to_string() != "_" && name == "_" => {
156+
let ty = ty_to_string(ty);
157+
(format!(" for `{}`", ty),
158+
format!("the explicit type `{}`, with the type parameters specified", ty))
159+
}
155160
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
156161
let ty = ty_to_string(ty);
157162
(format!(" for `{}`", ty),

src/test/ui/issues/issue-12187-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let &v = new();
55
| -^
66
| ||
77
| |cannot infer type
8-
| consider giving this pattern the explicit type `&T`, where the type parameter `_` is specified
8+
| consider giving this pattern the explicit type `&T`, with the type parameters specified
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-12187-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let &v = new();
55
| -^
66
| ||
77
| |cannot infer type
8-
| consider giving this pattern the explicit type `&T`, where the type parameter `_` is specified
8+
| consider giving this pattern the explicit type `&T`, with the type parameters specified
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-7813.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&[_; 0]`
44
LL | let v = &[];
55
| - ^^^ cannot infer type
66
| |
7-
| consider giving `v` the explicit type `&[_; 0]`, where the type parameter `_` is specified
7+
| consider giving `v` the explicit type `&[_; 0]`, with the type parameters specified
88

99
error: aborting due to previous error
1010

src/test/ui/type/type-check/cannot_infer_local_or_array.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `[_; 0]`
44
LL | let x = [];
55
| - ^^ cannot infer type
66
| |
7-
| consider giving `x` the explicit type `[_; 0]`, where the type parameter `_` is specified
7+
| consider giving `x` the explicit type `[_; 0]`, with the type parameters specified
88

99
error: aborting due to previous error
1010

src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `std::option::Option<T>`
22
--> $DIR/unboxed-closures-failed-recursive-fn-2.rs:16:32
33
|
44
LL | let mut closure0 = None;
5-
| ------------ consider giving `closure0` the explicit type `std::option::Option<T>`, where the type parameter `_` is specified
5+
| ------------ consider giving `closure0` the explicit type `std::option::Option<T>`, with the type parameters specified
66
...
77
LL | return c();
88
| ^^^ cannot infer type

0 commit comments

Comments
 (0)