mirror of
https://github.com/rust-lang/rust.git
synced 2025-11-30 22:07:58 +00:00
During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`:
```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
--> $DIR/missing-if-let-or-let-else.rs:14:25
|
LL | let Some(x) = foo() {
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
|
help: you might have meant to use `if let`
|
LL | if let Some(x) = foo() {
| ++
help: alternatively, you might have meant to use `let else`
|
LL | let Some(x) = foo() else {
| ++++
```
25 lines
644 B
Rust
25 lines
644 B
Rust
fn a() {
|
|
let Some(x) = foo() { //~ ERROR expected one of
|
|
//~^ HELP you might have meant to use `if let`
|
|
let y = x;
|
|
}
|
|
}
|
|
fn b() {
|
|
let Some(x) = foo() { //~ ERROR expected one of
|
|
//~^ HELP you might have meant to use `let else`
|
|
return;
|
|
}
|
|
}
|
|
fn c() {
|
|
let Some(x) = foo() { //~ ERROR expected one of
|
|
//~^ HELP you might have meant to use `if let`
|
|
//~| HELP alternatively, you might have meant to use `let else`
|
|
// The parser check happens pre-macro-expansion, so we don't know for sure.
|
|
println!("{x}");
|
|
}
|
|
}
|
|
fn foo() -> Option<i32> {
|
|
Some(42)
|
|
}
|
|
fn main() {}
|