Suggest giving return type to closures on E0282

This commit is contained in:
Esteban Küber 2019-08-13 16:41:43 -07:00
parent 939c1cb349
commit 806476c840
13 changed files with 199 additions and 90 deletions

View file

@ -2,10 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/E0282.rs:2:9
|
LL | let x = "hello".chars().rev().collect();
| ^
| |
| cannot infer type
| consider giving `x` a type
| ^ consider giving `x` a type
error: aborting due to previous error

View file

@ -2,10 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/for-loop-unconstrained-element-type.rs:8:14
|
LL | for i in Vec::new() { }
| ^^^^^^^^^^
| |
| cannot infer type
| the element type for this iterator is not specified
| ^^^^^^^^^^ the element type for this iterator is not specified
error: aborting due to previous error

View file

@ -1,10 +1,12 @@
error[E0282]: type annotations needed for the closure
error[E0282]: type annotations needed for the closure `fn((), ()) -> std::result::Result<(), _>`
--> $DIR/cannot-infer-closure.rs:3:9
|
LL | let x = |a: (), b: ()| {
| - consider giving `x` a boxed closure type like `Box<dyn Fn((), ()) -> std::result::Result<(), _>>`
LL | Err(a)?;
| ^^^^^^^ cannot infer type
help: give this closure an explicit return type without `_` placeholders
|
LL | let x = |a: (), b: ()| -> std::result::Result<(), _> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -2,10 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/issue-18159.rs:2:9
|
LL | let x;
| ^
| |
| cannot infer type
| consider giving `x` a type
| ^ consider giving `x` a type
error: aborting due to previous error

View file

@ -2,10 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/match-unresolved-one-arm.rs:4:9
|
LL | let x = match () {
| ^
| |
| cannot infer type
| consider giving `x` a type
| ^ consider giving `x` a type
error: aborting due to previous error

View file

@ -0,0 +1,3 @@
fn main() {
let _v = || -> _ { [] }; //~ ERROR type annotations needed for the closure
}

View file

@ -0,0 +1,13 @@
error[E0282]: type annotations needed for the closure `fn() -> [_; 0]`
--> $DIR/suggest-closure-return-type-1.rs:2:24
|
LL | let _v = || -> _ { [] };
| ^^ cannot infer type
help: give this closure an explicit return type without `_` placeholders
|
LL | let _v = || -> [_; 0] { [] };
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.

View file

@ -0,0 +1,3 @@
fn main() {
let _v = || { [] }; //~ ERROR type annotations needed for the closure
}

View file

@ -0,0 +1,13 @@
error[E0282]: type annotations needed for the closure `fn() -> [_; 0]`
--> $DIR/suggest-closure-return-type-2.rs:2:19
|
LL | let _v = || { [] };
| ^^ cannot infer type
help: give this closure an explicit return type without `_` placeholders
|
LL | let _v = || -> [_; 0] { [] };
| ^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.

View file

@ -0,0 +1,3 @@
fn main() {
let _v = || []; //~ ERROR type annotations needed for the closure
}

View file

@ -0,0 +1,13 @@
error[E0282]: type annotations needed for the closure `fn() -> [_; 0]`
--> $DIR/suggest-closure-return-type-3.rs:2:17
|
LL | let _v = || [];
| ^^ cannot infer type
help: give this closure an explicit return type without `_` placeholders
|
LL | let _v = || -> [_; 0] { [] };
| ^^^^^^^^^^^ ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.