未验证 提交 1b62bb67 编写于 作者: T Tyler Mandry 提交者: GitHub

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
......@@ -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()))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册