Skip to content

Matching on exhaustive enum errors with const_if_match #66756

New issue

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

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

Already on GitHub? # to your account

Closed
jhpratt opened this issue Nov 25, 2019 · 3 comments · Fixed by #66788
Closed

Matching on exhaustive enum errors with const_if_match #66756

jhpratt opened this issue Nov 25, 2019 · 3 comments · Fixed by #66788
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jhpratt
Copy link
Member

jhpratt commented Nov 25, 2019

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13a9fbc4251d7db80f5d63b1dc35a98b

#![feature(const_if_match)]

enum E {
    A,
    B,
    C
}

const fn f(e: E) {
    match e {
        E::A => {}
        E::B => {}
        E::C => {}
    }
}
error[E0723]: const fn with unreachable code is not stable
  --> src/lib.rs:10:11
   |
10 |     match e {
   |           ^
   |
   = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
   = help: add `#![feature(const_fn)]` to the crate attributes to enable

CC: #49146, @ecstatic-morse

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. F-const_if_match T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2019
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Nov 25, 2019

The error is emitted from this match arm. Adding #![feature(const_fn)] does enable the example above. Interestingly, no Unreachable terminator appears in the MIR for that function. This suggests that we are running const checks before a cleanup pass that removes Unreachable terminators for exhaustive match expressions.

@oli-obk We have a few choices here. I am leaning towards just removing Unreachable from the min_const_fn checks. What do you think?

cc @rust-lang/wg-const-eval

@ecstatic-morse ecstatic-morse self-assigned this Nov 25, 2019
@Centril
Copy link
Contributor

Centril commented Nov 25, 2019

I am leaning towards just removing Unreachable from the min_const_fn checks. What do you think?

Let's gate the removal on const_if_match for now to make sure we don't accidentally allow anything on stable.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 26, 2019

I am leaning towards just removing Unreachable from the min_const_fn checks. What do you think?

Oh yea, I just left it in there so we don't accidentally allow something. I couldn't figure out how to trigger it, so I preferred to deny it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants