Detect missing else in let statement#156949
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors squash msg="fix issue-156949" |
This comment has been minimized.
This comment has been minimized.
|
🔨 4 commits were squashed into 6bbafec. |
7b541ec to
6bbafec
Compare
6bbafec to
4946c86
Compare
There was a problem hiding this comment.
We can address this later, but we are emitting two errors per mistake here, where we should strive to emit a single one. I originally envisioned dealing with this during parse instead of during resolution. Doing this during resolution does give us the benefit of being able to identify that foo is a local binding instead of a struct, which increases the accuracy of the diagnostic, so that's reasonable.
There was a problem hiding this comment.
I think I should just handle this in the parser. I think it's not worth to use stash and try_steal_modify_and_emit_err on this simple issue.
|
@estebank Fixed |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
d7ba54d to
c68037d
Compare
This comment has been minimized.
This comment has been minimized.
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
7d6bb50 to
47e8efe
Compare
This comment has been minimized.
This comment has been minimized.
47e8efe to
fcb6c44
Compare
This comment has been minimized.
This comment has been minimized.
1243bc5 to
7f175f8
Compare
|
I change the code to error: expected identifier, found keyword `return`
--> $DIR/detect-missing-else-in-let-1.rs:4:23
|
LL | let Some(a) = foo{return;};
| --- ^^^^^^ expected identifier, found keyword
| |
| while parsing this struct
|
help: escape `return` to use it as an identifier
|
LL | let Some(a) = foo{r#return;};
| ++
help: you might have meant to write a diverging block on a refutable `let` statement by using `let-else`
for more information, visit <https://doc.rust-lang.org/beta/rust-by-example/flow_control/let_else.html>
|
LL | let Some(a) = foo else {return;};
| ++++
error: aborting due to 1 previous error@rustbot ready |
This comment has been minimized.
This comment has been minimized.
7f175f8 to
0ea7df6
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
Fixes #135857
I add the help message in rustc_resolve. It now will display something like this:
r? estebank