Rollup merge of #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 #114529
This commit is contained in:
commit
4f4b38c40f
3 changed files with 58 additions and 4 deletions
|
@ -625,10 +625,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
// 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));
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
// Recurse without `enclosing_breakables` borrowed.
|
||||
e_ty = self.check_expr_with_hint(e, coerce_to);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue