Skip to content

Commit

Permalink
Rollup merge of rust-lang#71691 - ecstatic-morse:const-unreachable, r…
Browse files Browse the repository at this point in the history
…=oli-obk,RalfJung

Allow `Unreachable` terminators unconditionally in const-checking

If we ever actually reach an `Unreachable` terminator while executing, the MIR is ill-formed or the user's program is UB due to something like `unreachable_unchecked`. I don't think we need to forbid these in `qualify_min_const_fn`.

r? @oli-obk
  • Loading branch information
tmandry authored Apr 30, 2020
2 parents a8e0511 + a1aff18 commit 1b62bb6
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ fn check_terminator(
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::Goto { .. }
| TerminatorKind::Return
| TerminatorKind::Resume => Ok(()),
| TerminatorKind::Resume
| TerminatorKind::Unreachable => Ok(()),

TerminatorKind::Drop { location, .. } => check_place(tcx, *location, span, def_id, body),
TerminatorKind::DropAndReplace { location, value, .. } => {
Expand All @@ -356,12 +357,7 @@ fn check_terminator(
check_operand(tcx, discr, span, def_id, body)
}

// FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
TerminatorKind::Unreachable if feature_allowed(tcx, def_id, sym::const_if_match) => Ok(()),

TerminatorKind::Abort | TerminatorKind::Unreachable => {
Err((span, "const fn with unreachable code is not stable".into()))
}
TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())),
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
Err((span, "const fn generators are unstable".into()))
}
Expand Down

0 comments on commit 1b62bb6

Please sign in to comment.