Add more detail to type inference error

When encountering code where type inference fails, add more actionable
information:

```
fn main() {
    let foo = Vec::new();
}
```

```
error[E0282]: type annotations needed for `std::vec::Vec<_>`
  --> $DIR/vector-no-ann.rs:2:16
   |
LL |     let foo = Vec::new();
   |         ---   ^^^^^^^^ cannot infer type for `T`
   |         |
   |         consider giving `foo` the type `std::vec::Vec<_>` with the type parameter `T` specified
```

We still need to modify type printing to optionally accept a
`TypeVariableTable` in order to properly print `std::vec::Vec<T>`.

CC #25633.
This commit is contained in:
Esteban Küber 2019-05-30 10:19:58 -07:00
parent 7840a0b753
commit 8bb094dac5
19 changed files with 82 additions and 42 deletions

View file

@ -4,5 +4,5 @@ fn new<T>() -> &'static T {
fn main() {
let &v = new();
//~^ ERROR type annotations needed [E0282]
//~^ ERROR type annotations needed
}

View file

@ -1,4 +1,4 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `&_`
--> $DIR/issue-12187-1.rs:6:10
|
LL | let &v = new();

View file

@ -4,5 +4,5 @@ fn new<'r, T>() -> &'r T {
fn main() {
let &v = new();
//~^ ERROR type annotations needed [E0282]
//~^ ERROR type annotations needed
}

View file

@ -1,4 +1,4 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `&_`
--> $DIR/issue-12187-2.rs:6:10
|
LL | let &v = new();

View file

@ -1,10 +1,10 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `B<_>`
--> $DIR/issue-17551.rs:6:15
|
LL | let foo = B(marker::PhantomData);
| --- ^ cannot infer type for `T`
| |
| consider giving `foo` a type
| consider giving `foo` the type `B<_>` with the type parameter `T` specified
error: aborting due to previous error

View file

@ -1,4 +1,4 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `&(_,)`
--> $DIR/issue-20261.rs:4:11
|
LL | for (ref i,) in [].iter() {

View file

@ -1,8 +1,8 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `Expr<'_, _>`
--> $DIR/issue-23046.rs:17:15
|
LL | let ex = |x| {
| ^ consider giving this closure parameter a type
| ^ consider giving this closure parameter the type `Expr<'_, _>` with the type parameter `VAR` specified
error: aborting due to previous error

View file

@ -1,4 +1,4 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `(std::sync::mpsc::Sender<Foo<_>>, std::sync::mpsc::Receiver<Foo<_>>)`
--> $DIR/issue-25368.rs:11:17
|
LL | let (tx, rx) = channel();

View file

@ -1,10 +1,10 @@
error[E0282]: type annotations needed
error[E0282]: type annotations needed for `&[_; 0]`
--> $DIR/issue-7813.rs:2:13
|
LL | let v = &[];
| - ^^^ cannot infer type
| |
| consider giving `v` a type
| consider giving `v` the type `&[_; 0]` with the type parameter `_` specified
error: aborting due to previous error