You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bcf6cb7
Browse filesBrowse the repository at this point in the historyBrowse files
Rollup merge of #156949 - bb1yd:detect-missing-else, r=estebank
Detect missing else in let statement
Fixes#135857
I add the help message in rustc_resolve. It now will display something like this:
```rust
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
"you might have meant to write a diverging block on a refutable `let` statement by using `let-else`
4658
+
for more information, visit <https://doc.rust-lang.org/beta/rust-by-example/flow_control/let_else.html>",
error: expected identifier, found keyword `return`
2
+
--> $DIR/detect-missing-else-in-let-1.rs:4:23
3
+
|
4
+
LL | let Some(a) = foo{return;};
5
+
| --- ^^^^^^ expected identifier, found keyword
6
+
| |
7
+
| while parsing this struct
8
+
|
9
+
help: escape `return` to use it as an identifier
10
+
|
11
+
LL | let Some(a) = foo{r#return;};
12
+
| ++
13
+
help: you might have meant to write a diverging block on a refutable `let` statement by using `let-else`
14
+
for more information, visit <https://doc.rust-lang.org/beta/rust-by-example/flow_control/let_else.html>
error: expected identifier, found keyword `return`
2
+
--> $DIR/detect-missing-else-in-let-2.rs:6:19
3
+
|
4
+
LL | let bar = foo{return;};
5
+
| --- ^^^^^^ expected identifier, found keyword
6
+
| |
7
+
| while parsing this struct
8
+
|
9
+
help: escape `return` to use it as an identifier
10
+
|
11
+
LL | let bar = foo{r#return;};
12
+
| ++
13
+
help: you might have meant to write a diverging block on a refutable `let` statement by using `let-else`
14
+
for more information, visit <https://doc.rust-lang.org/beta/rust-by-example/flow_control/let_else.html>
0 commit comments