forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#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 rust-lang#48594 (comment) r? `@compiler-errors`
- Loading branch information
Showing
5 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
LL | let _ = 'label: 1 + 1; | ||
| ^ expected `while`, `for`, `loop` or `{` after a label | ||
| | ||
help: consider removing the label | ||
| | ||
LL - let _ = 'label: 1 + 1; | ||
LL + let _ = 1 + 1; | ||
| | ||
|
||
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[E0308]: mismatched types | ||
--> $DIR/recover-labeled-non-block-expr.rs:4:33 | ||
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 _recovery_witness: () = 0; | ||
| -- ^ expected `()`, found integer | ||
| | | ||
| expected due to this | ||
LL | let _val = 'label: { (1, if other == 3 { break 'label (2, 3) } else { other }) }; | ||
| + + | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |