Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Unreachable terminators through min_const_fn checks #66788

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 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,27 @@
// 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 => {}
}
}

const fn g(e: E) {
match e {
_ => {}
}
}

fn main() {}