forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#75931 - estebank:suggest-if-let, r=petrochenkov
Suggest `if let x = y` when encountering `if x = y` Detect potential cases where `if let` was meant but `let` was left out. Fix rust-lang#44990.
- Loading branch information
Showing
11 changed files
with
268 additions
and
102 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
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 @@ | ||
fn main() { | ||
let foo = Some(0); | ||
let bar = None; | ||
if Some(x) = foo {} //~ ERROR cannot find value `x` in this scope | ||
if Some(foo) = bar {} //~ ERROR mismatched types | ||
if 3 = foo {} //~ ERROR mismatched types | ||
//~^ ERROR mismatched types | ||
if Some(3) = foo {} //~ ERROR mismatched types | ||
} |
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,60 @@ | ||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/if-let-typo.rs:4:13 | ||
| | ||
LL | if Some(x) = foo {} | ||
| ^ not found in this scope | ||
| | ||
help: you might have meant to use pattern matching | ||
| | ||
LL | if let Some(x) = foo {} | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/if-let-typo.rs:5:8 | ||
| | ||
LL | if Some(foo) = bar {} | ||
| ^^^^^^^^^^^^^^^ expected `bool`, found `()` | ||
| | ||
help: you might have meant to use pattern matching | ||
| | ||
LL | if let Some(foo) = bar {} | ||
| ^^^ | ||
help: you might have meant to compare for equality | ||
| | ||
LL | if Some(foo) == bar {} | ||
| ^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/if-let-typo.rs:6:12 | ||
| | ||
LL | if 3 = foo {} | ||
| ^^^ expected integer, found enum `std::option::Option` | ||
| | ||
= note: expected type `{integer}` | ||
found enum `std::option::Option<{integer}>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/if-let-typo.rs:6:8 | ||
| | ||
LL | if 3 = foo {} | ||
| ^^^^^^^ expected `bool`, found `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/if-let-typo.rs:8:8 | ||
| | ||
LL | if Some(3) = foo {} | ||
| ^^^^^^^^^^^^^ expected `bool`, found `()` | ||
| | ||
help: you might have meant to use pattern matching | ||
| | ||
LL | if let Some(3) = foo {} | ||
| ^^^ | ||
help: you might have meant to compare for equality | ||
| | ||
LL | if Some(3) == foo {} | ||
| ^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0425. | ||
For more information about an error, try `rustc --explain E0308`. |
Oops, something went wrong.