Rollup merge of #97759 - WaffleLapkin:recover_label_expr, r=compiler-errors
Suggest adding `{}` for `'label: non_block_expr`
Adds suggestions like this:
```text
help: consider enclosing expression in a block
|
3 | 'l {0};
| + +
```
inspired by https://github.com/rust-lang/rust/issues/48594#issuecomment-1146744400
r? ``@compiler-errors``
This commit is contained in:
commit
554674b98c
5 changed files with 189 additions and 16 deletions
|
|
@ -47,6 +47,12 @@ error: expected `while`, `for`, `loop` or `{` after a label
|
|||
|
|
||||
LL | 'l4 0;
|
||||
| ^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider removing the label
|
||||
|
|
||||
LL - 'l4 0;
|
||||
LL + 0;
|
||||
|
|
||||
|
||||
error: labeled expression must be followed by `:`
|
||||
--> $DIR/labeled-no-colon-expr.rs:8:9
|
||||
|
|
|
|||
27
src/test/ui/parser/recover-labeled-non-block-expr.fixed
Normal file
27
src/test/ui/parser/recover-labeled-non-block-expr.fixed
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// run-rustfix
|
||||
#![feature(label_break_value)]
|
||||
fn main() {
|
||||
let _ = 1 + 1; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
match () { () => {}, }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
'label: { match () { () => break 'label, } }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
#[allow(unused_labels)]
|
||||
'label: { match () { () => 'lp: loop { break 'lp 0 }, } }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
let x = 1;
|
||||
let _i = 'label: { match x { //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
0 => 42,
|
||||
1 if false => break 'label 17,
|
||||
1 => {
|
||||
if true {
|
||||
break 'label 13
|
||||
} else {
|
||||
break 'label 0;
|
||||
}
|
||||
}
|
||||
_ => 1,
|
||||
} };
|
||||
|
||||
let other = 3;
|
||||
let _val = 'label: { (1, if other == 3 { break 'label (2, 3) } else { other }) }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
}
|
||||
|
|
@ -1,5 +1,27 @@
|
|||
// run-rustfix
|
||||
#![feature(label_break_value)]
|
||||
fn main() {
|
||||
'label: 1 + 1; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
let _ = 'label: 1 + 1; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
let _recovery_witness: () = 0; //~ ERROR mismatched types
|
||||
'label: match () { () => {}, }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
'label: match () { () => break 'label, }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
#[allow(unused_labels)]
|
||||
'label: match () { () => 'lp: loop { break 'lp 0 }, }; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
let x = 1;
|
||||
let _i = 'label: match x { //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
0 => 42,
|
||||
1 if false => break 'label 17,
|
||||
1 => {
|
||||
if true {
|
||||
break 'label 13
|
||||
} else {
|
||||
break 'label 0;
|
||||
}
|
||||
}
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
let other = 3;
|
||||
let _val = 'label: (1, if other == 3 { break 'label (2, 3) } else { other }); //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,75 @@
|
|||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:2:13
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:4:21
|
||||
|
|
||||
LL | 'label: 1 + 1;
|
||||
| ^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:4:33
|
||||
LL | let _ = 'label: 1 + 1;
|
||||
| ^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
LL | let _recovery_witness: () = 0;
|
||||
| -- ^ expected `()`, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
help: consider removing the label
|
||||
|
|
||||
LL - let _ = 'label: 1 + 1;
|
||||
LL + let _ = 1 + 1;
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:6:13
|
||||
|
|
||||
LL | 'label: match () { () => {}, };
|
||||
| ^^^^^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider removing the label
|
||||
|
|
||||
LL - 'label: match () { () => {}, };
|
||||
LL + match () { () => {}, };
|
||||
|
|
||||
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:7:13
|
||||
|
|
||||
LL | 'label: match () { () => break 'label, };
|
||||
| ^^^^^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider enclosing expression in a block
|
||||
|
|
||||
LL | 'label: { match () { () => break 'label, } };
|
||||
| + +
|
||||
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:9:13
|
||||
|
|
||||
LL | 'label: match () { () => 'lp: loop { break 'lp 0 }, };
|
||||
| ^^^^^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider enclosing expression in a block
|
||||
|
|
||||
LL | 'label: { match () { () => 'lp: loop { break 'lp 0 }, } };
|
||||
| + +
|
||||
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:12:22
|
||||
|
|
||||
LL | let _i = 'label: match x {
|
||||
| ^^^^^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider enclosing expression in a block
|
||||
|
|
||||
LL ~ let _i = 'label: { match x {
|
||||
LL | 0 => 42,
|
||||
LL | 1 if false => break 'label 17,
|
||||
LL | 1 => {
|
||||
LL | if true {
|
||||
LL | break 'label 13
|
||||
...
|
||||
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:26:24
|
||||
|
|
||||
LL | let _val = 'label: (1, if other == 3 { break 'label (2, 3) } else { other });
|
||||
| ^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
|
||||
help: consider enclosing expression in a block
|
||||
|
|
||||
LL | let _val = 'label: { (1, if other == 3 { break 'label (2, 3) } else { other }) };
|
||||
| + +
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue