forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#117382 - gurry:114529-ice-const-eval, r=oli-obk Fail typeck for illegal break-with-value This is fixes the issue wherein typeck was succeeding for break-with-value exprs at illegal locations such as inside `while`, `while let` and `for` loops which eventually caused an ICE during MIR interpretation for const eval. Now we fail typeck for such code which prevents faulty MIR from being generated and interpreted, thus fixing the ICE. Fixes rust-lang#114529
- Loading branch information
Showing
3 changed files
with
58 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Regression test for issue #114529 | ||
// Tests that we do not ICE during const eval for a | ||
// break-with-value in contexts where it is illegal | ||
|
||
#[allow(while_true)] | ||
fn main() { | ||
[(); { | ||
while true { | ||
break 9; //~ ERROR `break` with value from a `while` loop | ||
}; | ||
51 | ||
}]; | ||
|
||
[(); { | ||
while let Some(v) = Some(9) { | ||
break v; //~ ERROR `break` with value from a `while` loop | ||
}; | ||
51 | ||
}]; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/typeck/issue-114529-illegal-break-with-value.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,29 @@ | ||
error[E0571]: `break` with value from a `while` loop | ||
--> $DIR/issue-114529-illegal-break-with-value.rs:9:13 | ||
| | ||
LL | while true { | ||
| ---------- you can't `break` with a value in a `while` loop | ||
LL | break 9; | ||
| ^^^^^^^ can only break with a value inside `loop` or breakable block | ||
| | ||
help: use `break` on its own without a value inside this `while` loop | ||
| | ||
LL | break; | ||
| ~~~~~ | ||
|
||
error[E0571]: `break` with value from a `while` loop | ||
--> $DIR/issue-114529-illegal-break-with-value.rs:16:13 | ||
| | ||
LL | while let Some(v) = Some(9) { | ||
| --------------------------- you can't `break` with a value in a `while` loop | ||
LL | break v; | ||
| ^^^^^^^ can only break with a value inside `loop` or breakable block | ||
| | ||
help: use `break` on its own without a value inside this `while` loop | ||
| | ||
LL | break; | ||
| ~~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0571`. |