Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --<!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
<!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
I can't reproduce this on the latest nightly. Can you confirm that this doesn't reproduce anymore?
This may only be triggerable with a rustc that was built with debug assertions on
Yes, hence the label :sweat_smile:
No longer needs debug assertions to crash :tada:
`
Edit: Ignore it. Wrong bisection. For some reason it was bisecting to 2023-10-04 on my machine despite the fact that the issue was reported much earlier than this date.
The issue occurs because the interpreter tries to assign the value from to a temporary MIR local of type which produces a type mismatch and results in the ICE. Such faulty MIR should not have been generated. However, the while loop, although detected as malformed during AST lowering, successfully typecks. Had it not and had been set to , the MIR would not have been generated. Therefore as far as I understand the solution is to fail typeck and set to for code like this. claim

Discussion:
} }; <del> // If the loop context is not a `loop { }`, then break with // a value is illegal, and `opt_coerce_to` will be `None`. // Just set expectation to error in that case. let coerce_to = opt_coerce_to.unwrap_or_else(|| Ty::new_misc_error(tcx)); </del> <ins> let coerce_to = match opt_coerce_to { Some(c) => c, None => { // If the loop context is not a `loop { }`, then break with // a value is illegal, and `opt_coerce_to` will be `None`. // Return error in that case (#114529). return Ty::new_misc_error(tcx); } }; </ins> // Recurse without `enclosing_breakables` borrowed. e_ty = self.check_expr_with_hint(e, coerce_to);

<ins> // 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 }]; } </ins>

<ins> 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`. </ins>