From 2626cfbb586800144e0fde579849f4afc813d5ff Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 11:36:53 -0800 Subject: [PATCH 1/3] Allow `Unreachable` terminators behind `const_if_match` --- src/librustc_mir/transform/qualify_min_const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 71f13c169d41e..81f4c277f4d76 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -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())) } From 582affd657701aa8fff42b9e0eb32d23796167b5 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 11:37:16 -0800 Subject: [PATCH 2/3] Add regression test for #66756 --- .../exhaustive-c-like-enum-match.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs new file mode 100644 index 0000000000000..d24179d856f46 --- /dev/null +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -0,0 +1,27 @@ +// Test for + +// 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() {} From a626bf68b882d41dc608692dc52b2a9fb06bff26 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 12:13:15 -0800 Subject: [PATCH 3/3] Remove test for #66758 --- .../ui/consts/control-flow/exhaustive-c-like-enum-match.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs index d24179d856f46..9e22151f2e9ee 100644 --- a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -18,10 +18,4 @@ const fn f(e: E) { } } -const fn g(e: E) { - match e { - _ => {} - } -} - fn main() {}