Auto merge of #103636 - chenyukang:yukang/fix-103587-sugg-if-let, r=jackh276,davidtwco

Recover from common if let syntax mistakes/typos

Fixes #103587
This commit is contained in:
bors 2022-11-10 05:19:10 +00:00
commit 11fa0850f0
11 changed files with 184 additions and 4 deletions

View file

@ -14,6 +14,11 @@ error[E0308]: mismatched types
|
LL | if Err(err) = File::open("hello.txt") {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | if let Err(err) = File::open("hello.txt") {
| +++
error: aborting due to 2 previous errors

View file

@ -0,0 +1,12 @@
fn main() {
let x = Some(123);
if let Some(_) == x {}
//~^ ERROR expected `=`, found `==`
if Some(_) = x {}
//~^ ERROR mismatched types
if None = x { }
//~^ ERROR mismatched types
}

View file

@ -0,0 +1,40 @@
error: expected `=`, found `==`
--> $DIR/issue-103587.rs:4:20
|
LL | if let Some(_) == x {}
| ^^
|
help: consider using `=` here
|
LL | if let Some(_) = x {}
| ~
error[E0308]: mismatched types
--> $DIR/issue-103587.rs:7:8
|
LL | if Some(_) = x {}
| ^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | if let Some(_) = x {}
| +++
error[E0308]: mismatched types
--> $DIR/issue-103587.rs:10:8
|
LL | if None = x { }
| ^^^^^^^^ expected `bool`, found `()`
|
help: you might have meant to use pattern matching
|
LL | if let None = x { }
| +++
help: you might have meant to compare for equality
|
LL | if None == x { }
| +
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -25,12 +25,22 @@ error[E0308]: mismatched types
|
LL | if Some(x) = foo {}
| ^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | if let Some(x) = foo {}
| +++
error[E0308]: mismatched types
--> $DIR/if-let-typo.rs:6:8
|
LL | if Some(foo) = bar {}
| ^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | if let Some(foo) = bar {}
| +++
error[E0308]: mismatched types
--> $DIR/if-let-typo.rs:7:8
@ -51,6 +61,11 @@ error[E0308]: mismatched types
|
LL | if Some(3) = foo {}
| ^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | if let Some(3) = foo {}
| +++
error: aborting due to 7 previous errors

View file

@ -23,6 +23,11 @@ error[E0308]: mismatched types
|
LL | Some(reference) = cache.data.get(key) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: consider adding `let`
|
LL | let Some(reference) = cache.data.get(key) {
| +++
error: aborting due to 3 previous errors