-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest is_some or let when encountering Option and bool type mismatch
- Loading branch information
1 parent
cc9b259
commit 38ada60
Showing
5 changed files
with
85 additions
and
4 deletions.
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
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,9 @@ | ||
#![cfg_attr(let_chains, feature(let_chains))] | ||
|
||
fn foo(x: Option<i32>) { | ||
if true && x {} | ||
//~^ ERROR mismatched types | ||
//~| HELP use `Option::is_some` to test if the `Option` has a value | ||
} | ||
|
||
fn main() {} |
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,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/option-to-bool.rs:4:16 | ||
| | ||
LL | if true && x {} | ||
| ^ expected `bool`, found enum `Option` | ||
| | ||
= note: expected type `bool` | ||
found enum `Option<i32>` | ||
help: use `Option::is_some` to test if the `Option` has a value | ||
| | ||
LL | if true && x.is_some() {} | ||
| ++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |