-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest adding {}
for 'label: non_block_expr
#97759
Changes from 3 commits
f21c0a2
c6e5bb3
f06f051
4f85a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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 | ||
} |
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 | ||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can someone explain where the second part of the suggestion ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestions only render up to 5 lines i think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that it'd show multiple parts :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a bug in the rendering code. Your suggestion is still MachineApplicable so it will apply just fine, it's just the rendered code will be cut off. I don't know if there's much you can do to fix it in this PR specifically, but maybe you could file a bug, or look into fixing the rendering code to omit lines in the middle? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll look into it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a "bug", but rather a non-implementation of the logic for multiple "windows" into the code, like span labels have. |
||
|
||
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you actually use
?
here, move the body of the closure to below, and remove the?
on line 1614?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other if branches also return
Result
s, so I don't think it makes sense to do thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, oops, I thought there was only two if branches. I should've clicked the button to reveal the lines above 😓