Skip to content

Commit 8547ea3

Browse files
authored
Rollup merge of #66788 - ecstatic-morse:const-fn-unreachable, r=Centril
Allow `Unreachable` terminators through `min_const_fn` checks Resolves #66756. This allows `Unreachable` terminators through the `min_const_fn` checks if `#![feature(const_if_match)]` is enabled. We could probably just allow them with no feature flag, but it seems okay to be conservative here. r? @oli-obk
2 parents 7f166e4 + a626bf6 commit 8547ea3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc_mir/transform/qualify_min_const_fn.rs

+3
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ fn check_terminator(
337337
check_operand(tcx, discr, span, def_id, body)
338338
}
339339

340+
// FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
341+
TerminatorKind::Unreachable if tcx.features().const_if_match => Ok(()),
342+
340343
| TerminatorKind::Abort | TerminatorKind::Unreachable => {
341344
Err((span, "const fn with unreachable code is not stable".into()))
342345
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test for <https://github.com/rust-lang/rust/issues/66756>
2+
3+
// check-pass
4+
5+
#![feature(const_if_match)]
6+
7+
enum E {
8+
A,
9+
B,
10+
C
11+
}
12+
13+
const fn f(e: E) {
14+
match e {
15+
E::A => {}
16+
E::B => {}
17+
E::C => {}
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)