Skip to content

Commit

Permalink
Rollup merge of #66788 - ecstatic-morse:const-fn-unreachable, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tmandry authored Nov 26, 2019
2 parents 7f166e4 + a626bf6 commit 8547ea3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ fn check_terminator(
check_operand(tcx, discr, span, def_id, body)
}

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

| TerminatorKind::Abort | TerminatorKind::Unreachable => {
Err((span, "const fn with unreachable code is not stable".into()))
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Test for <https://github.com/rust-lang/rust/issues/66756>

// check-pass

#![feature(const_if_match)]

enum E {
A,
B,
C
}

const fn f(e: E) {
match e {
E::A => {}
E::B => {}
E::C => {}
}
}

fn main() {}

0 comments on commit 8547ea3

Please sign in to comment.