Rollup merge of #68314 - oli-obk:true_unwind, r=eddyb

Stop treating `FalseEdges` and `FalseUnwind` as having semantic value for const eval

This change does not expose loops or conditions to stable const fns because we check those at the HIR level and in the regular const validity checks.

cc @ecstatic-morse

r? @eddyb
This commit is contained in:
Tyler Mandry 2020-01-17 17:28:22 -08:00 committed by GitHub
commit dd6a83875e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -309,7 +309,11 @@ fn check_terminator(
) -> McfResult {
let span = terminator.source_info.span;
match &terminator.kind {
TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::Resume => Ok(()),
TerminatorKind::FalseEdges { .. }
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::Goto { .. }
| TerminatorKind::Return
| TerminatorKind::Resume => Ok(()),
TerminatorKind::Drop { location, .. } => check_place(tcx, location, span, def_id, body),
TerminatorKind::DropAndReplace { location, value, .. } => {
@ -317,13 +321,10 @@ fn check_terminator(
check_operand(tcx, value, span, def_id, body)
}
TerminatorKind::FalseEdges { .. } | TerminatorKind::SwitchInt { .. }
if !feature_allowed(tcx, def_id, sym::const_if_match) =>
{
TerminatorKind::SwitchInt { .. } if !feature_allowed(tcx, def_id, sym::const_if_match) => {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
TerminatorKind::FalseEdges { .. } => Ok(()),
TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => {
check_operand(tcx, discr, span, def_id, body)
}
@ -367,13 +368,5 @@ fn check_terminator(
TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => {
check_operand(tcx, cond, span, def_id, body)
}
TerminatorKind::FalseUnwind { .. } if feature_allowed(tcx, def_id, sym::const_loop) => {
Ok(())
}
TerminatorKind::FalseUnwind { .. } => {
Err((span, "loops are not allowed in const fn".into()))
}
}
}