-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest unwrap/expect for let binding type mismatch
- Loading branch information
1 parent
a483969
commit e1a03a1
Showing
6 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn func() -> Option<i32> { | ||
Some(1) | ||
} | ||
|
||
fn main() { | ||
let v: i32 = Some(1); //~ ERROR mismatched types | ||
let v: i32 = None; //~ ERROR mismatched types | ||
|
||
let a = Some(1); | ||
let v: i32 = a; //~ ERROR mismatched types | ||
|
||
let b = Ok(1); | ||
let v: i32 = b; //~ ERROR mismatched types | ||
|
||
let c = Ok(false); | ||
let v: i32 = c; //~ ERROR mismatched types | ||
|
||
let v: i32 = func(); //~ ERROR mismatched types | ||
} |
81 changes: 81 additions & 0 deletions
81
tests/ui/mismatched_types/mismatch-ty-unwrap-expect.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:6:18 | ||
| | ||
LL | let v: i32 = Some(1); | ||
| --- ^^^^^^^ expected `i32`, found `Option<{integer}>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Option<{integer}>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:7:18 | ||
| | ||
LL | let v: i32 = None; | ||
| --- ^^^^ expected `i32`, found `Option<_>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Option<_>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:10:18 | ||
| | ||
LL | let v: i32 = a; | ||
| --- ^ expected `i32`, found `Option<{integer}>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Option<{integer}>` | ||
help: you may missing `unwrap` or `expect(...)` here | ||
| | ||
LL | let v: i32 = a.unwrap(); | ||
| +++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:13:18 | ||
| | ||
LL | let v: i32 = b; | ||
| --- ^ expected `i32`, found `Result<{integer}, _>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Result<{integer}, _>` | ||
help: you may missing `unwrap` or `expect(...)` here | ||
| | ||
LL | let v: i32 = b.unwrap(); | ||
| +++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:16:18 | ||
| | ||
LL | let v: i32 = c; | ||
| --- ^ expected `i32`, found `Result<bool, _>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Result<bool, _>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatch-ty-unwrap-expect.rs:18:18 | ||
| | ||
LL | let v: i32 = func(); | ||
| --- ^^^^^^ expected `i32`, found `Option<i32>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found enum `Option<i32>` | ||
help: you may missing `unwrap` or `expect(...)` here | ||
| | ||
LL | let v: i32 = func().unwrap(); | ||
| +++++++++ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters