Skip to content

Commit 1b62bb6

Browse files
authored
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
2 parents a8e0511 + a1aff18 commit 1b62bb6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/librustc_mir/transform/qualify_min_const_fn.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ fn check_terminator(
340340
| TerminatorKind::FalseUnwind { .. }
341341
| TerminatorKind::Goto { .. }
342342
| TerminatorKind::Return
343-
| TerminatorKind::Resume => Ok(()),
343+
| TerminatorKind::Resume
344+
| TerminatorKind::Unreachable => Ok(()),
344345

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

359-
// FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
360-
TerminatorKind::Unreachable if feature_allowed(tcx, def_id, sym::const_if_match) => Ok(()),
361-
362-
TerminatorKind::Abort | TerminatorKind::Unreachable => {
363-
Err((span, "const fn with unreachable code is not stable".into()))
364-
}
360+
TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())),
365361
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
366362
Err((span, "const fn generators are unstable".into()))
367363
}

0 commit comments

Comments
 (0)