forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#128701 - veera-sivarajan:fix-128604, r=estebank Don't Suggest Labeling `const` and `unsafe` Blocks Fixes rust-lang#128604 Previously, both anonymous constant blocks (E.g. The labeled block inside `['_'; 'block: { break 'block 1 + 2; }]`) and inline const blocks (E.g. `const { ... }`) were considered to be the same kind of blocks. This caused the compiler to incorrectly suggest labeling both the blocks when only anonymous constant blocks can be labeled. This PR adds an other enum variant to `Context` so that both the blocks can be handled appropriately. Also, adds some doc comments and removes unnecessary `&mut` in a couple of places.
- Loading branch information
Showing
5 changed files
with
166 additions
and
14 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
25 changes: 25 additions & 0 deletions
25
tests/ui/inline-const/break-inside-inline-const-issue-128604.rs
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,25 @@ | ||
fn main() { | ||
let _ = ['a'; { break 2; 1 }]; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
//~| HELP consider labeling this block to be able to break within it | ||
|
||
const { | ||
{ | ||
//~^ HELP consider labeling this block to be able to break within it | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
} | ||
}; | ||
|
||
const { | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
}; | ||
|
||
{ | ||
const { | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/ui/inline-const/break-inside-inline-const-issue-128604.stderr
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,39 @@ | ||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-inline-const-issue-128604.rs:15:9 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-inline-const-issue-128604.rs:21:13 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-inline-const-issue-128604.rs:2:21 | ||
| | ||
LL | let _ = ['a'; { break 2; 1 }]; | ||
| ^^^^^^^ cannot `break` outside of a loop or labeled block | ||
| | ||
help: consider labeling this block to be able to break within it | ||
| | ||
LL | let _ = ['a'; 'block: { break 'block 2; 1 }]; | ||
| +++++++ ++++++ | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-inline-const-issue-128604.rs:9:13 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
| | ||
help: consider labeling this block to be able to break within it | ||
| | ||
LL ~ 'block: { | ||
LL | | ||
LL ~ break 'block; | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0268`. |
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,34 @@ | ||
fn main() { | ||
let a = ["_"; unsafe { break; 1 + 2 }]; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
|
||
unsafe { | ||
{ | ||
//~^ HELP consider labeling this block to be able to break within it | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
} | ||
} | ||
|
||
unsafe { | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
} | ||
|
||
{ | ||
//~^ HELP consider labeling this block to be able to break within it | ||
unsafe { | ||
break; | ||
//~^ ERROR `break` outside of a loop or labeled block | ||
} | ||
} | ||
|
||
while 2 > 1 { | ||
unsafe { | ||
if true || false { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
tests/ui/unsafe/break-inside-unsafe-block-issue-128604.stderr
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,42 @@ | ||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:2:28 | ||
| | ||
LL | let a = ["_"; unsafe { break; 1 + 2 }]; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:14:9 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:8:13 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
| | ||
help: consider labeling this block to be able to break within it | ||
| | ||
LL ~ 'block: { | ||
LL | | ||
LL ~ break 'block; | ||
| | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:21:13 | ||
| | ||
LL | break; | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
| | ||
help: consider labeling this block to be able to break within it | ||
| | ||
LL ~ 'block: { | ||
LL | | ||
LL | unsafe { | ||
LL ~ break 'block; | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0268`. |