diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-11-26 17:56:25 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-26 17:56:25 -0600 |
| commit | 8547ea32db4a6f2c5b27827b30f372859de22fbb (patch) | |
| tree | 037952914f0ba47a34c90d43be9c92c19e940e7e | |
| parent | 7f166e44ff187b517342a5ace95665743b2d222f (diff) | |
| parent | a626bf68b882d41dc608692dc52b2a9fb06bff26 (diff) | |
| download | rust-8547ea32db4a6f2c5b27827b30f372859de22fbb.tar.gz rust-8547ea32db4a6f2c5b27827b30f372859de22fbb.zip | |
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
| -rw-r--r-- | src/librustc_mir/transform/qualify_min_const_fn.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 71f13c169d4..81f4c277f4d 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())) } 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 00000000000..9e22151f2e9 --- /dev/null +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -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() {} |
