Skip to content

Commit

Permalink
Rollup merge of rust-lang#68314 - oli-obk:true_unwind, r=eddyb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tmandry committed Jan 17, 2020
2 parents 66ce826 + cdc828e commit 0f849b9
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,22 @@ 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, .. } => {
check_place(tcx, location, span, def_id, body)?;
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)
}
Expand Down Expand Up @@ -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()))
}
}
}

0 comments on commit 0f849b9

Please sign in to comment.