Rollup merge of #71691 - ecstatic-morse:const-unreachable, r=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
This commit is contained in:
Tyler Mandry 2020-04-30 15:23:19 -07:00 committed by GitHub
commit 1b62bb67da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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, .. } => {
@ -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()))
}