Skip to content

Detect missing else in let statement#156949

Open
bb1yd wants to merge 1 commit into
rust-lang:mainfrom
bb1yd:detect-missing-else
Open

Detect missing else in let statement#156949
bb1yd wants to merge 1 commit into
rust-lang:mainfrom
bb1yd:detect-missing-else

Conversation

@bb1yd
Copy link
Copy Markdown
Contributor

@bb1yd bb1yd commented May 26, 2026

relevant issue:#135857

I add the help message in rustc_resolve. It now will display something like this:

error: expected identifier, found keyword `return`
 --> ./test.rs:8:24
  |
8 |      let Some(a) = bar{return;};
  |                    --- ^^^^^^ expected identifier, found keyword
  |                    |
  |                    while parsing this struct
  |
help: escape `return` to use it as an identifier
  |
8 |      let Some(a) = bar{r#return;};
  |                        ++

error[E0574]: expected struct, variant or union type, found local variable `bar`
 --> ./test.rs:8:20
  |
8 |      let Some(a) = bar{return;};
  |                    ^^^ not a struct, variant or union type
  |
help: try adding `else` here:
  |
8 |      let Some(a) = bar else {return;};
  |                        ++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0574`.

r? estebank

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 26, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 26, 2026

@bors squash msg="fix issue-156949"

@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 26, 2026

🔨 4 commits were squashed into 6bbafec.

@rust-bors rust-bors Bot force-pushed the detect-missing-else branch from 7b541ec to 6bbafec Compare May 26, 2026 14:21
@bb1yd bb1yd force-pushed the detect-missing-else branch from 6bbafec to 4946c86 Compare May 26, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants