Fail typeck for illegal break-with-value
This is fixes the issue wherein typeck was succeeding for break-with-value at illegal locations such as inside `while`, `while let` and `for` loops which eventually caused an ICE during MIR interpetation for const eval. Now we fail typeck for such code which prevents faulty MIR from being generated and interpreted, thus fixing the ICE.
This commit is contained in:
parent
98108dc26c
commit
0c8bdd0bf3
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