Account for cases where we can find the type arg name, but the local name is _

This commit is contained in:
Esteban Küber 2019-06-01 15:33:31 -07:00
parent 9616b333b2
commit e420f4410b
6 changed files with 10 additions and 5 deletions

View file

@ -152,6 +152,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// | the type parameter `E` is specified
// ```
let (ty_msg, suffix) = match &local_visitor.found_ty {
Some(ty) if &ty.to_string() != "_" && name == "_" => {
let ty = ty_to_string(ty);
(format!(" for `{}`", ty),
format!("the explicit type `{}`, with the type parameters specified", ty))
}
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
let ty = ty_to_string(ty);
(format!(" for `{}`", ty),

View file

@ -5,7 +5,7 @@ LL | let &v = new();
| -^
| ||
| |cannot infer type
| consider giving this pattern the explicit type `&T`, where the type parameter `_` is specified
| consider giving this pattern the explicit type `&T`, with the type parameters specified
error: aborting due to previous error

View file

@ -5,7 +5,7 @@ LL | let &v = new();
| -^
| ||
| |cannot infer type
| consider giving this pattern the explicit type `&T`, where the type parameter `_` is specified
| consider giving this pattern the explicit type `&T`, with the type parameters specified
error: aborting due to previous error

View file

@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&[_; 0]`
LL | let v = &[];
| - ^^^ cannot infer type
| |
| consider giving `v` the explicit type `&[_; 0]`, where the type parameter `_` is specified
| consider giving `v` the explicit type `&[_; 0]`, with the type parameters specified
error: aborting due to previous error

View file

@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `[_; 0]`
LL | let x = [];
| - ^^ cannot infer type
| |
| consider giving `x` the explicit type `[_; 0]`, where the type parameter `_` is specified
| consider giving `x` the explicit type `[_; 0]`, with the type parameters specified
error: aborting due to previous error

View file

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