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

Bad unreachable pattern error if an enum branch doesn't exist. #19143

Closed
ptal opened this issue Nov 20, 2014 · 1 comment
Closed

Bad unreachable pattern error if an enum branch doesn't exist. #19143

ptal opened this issue Nov 20, 2014 · 1 comment

Comments

@ptal
Copy link

ptal commented Nov 20, 2014

The code presented next reports:

$rustc test.rs 
test.rs:19:5: 19:15 error: unreachable pattern [E0001]
test.rs:19     LitBool(_) => PLitBool
               ^~~~~~~~~~
test.rs:19:5: 19:15 help: pass `--explain E0001` to see a detailed explanation
error: aborting due to previous error

But this is wrong, the error is because LitNil doesn't exist anymore. I guess the compiler should check that enum variants used in patterns exist before checking if they can be reached. The test.rs file code is:

#![feature(globs)]
extern crate syntax;
use syntax::ast::Lit_;
use syntax::ast::Lit_::*;
use LitTypePrinter::*;

pub fn lit_to_lit_printer(lit: &Lit_) -> LitTypePrinter
{
  match *lit {
    LitStr(_, _) => PLitStr,
    LitBinary(_) => PLitBinary,
    LitByte(_) => PLitByte,
    LitChar(_) => PLitChar,
    LitInt(_, _) => PLitInt,
    LitFloat(_, _) => PLitFloat,
    LitFloatUnsuffixed(_) => PLitFloatUnsuffixed,
    LitNil => PLitNil,
    LitBool(_) => PLitBool
  }
}

pub enum LitTypePrinter
{
  PLitStr,
  PLitBinary,
  PLitByte,
  PLitChar,
  PLitInt,
  PLitFloat,
  PLitFloatUnsuffixed,
  PLitNil,
  PLitBool
}

fn main() {
  lit_to_lit_printer(&LitChar('a'));
}
@ghost
Copy link

ghost commented Dec 8, 2014

I'm going to close this. As of master, this will indeed still fail but also produce a warning that is more informative. See #19115. Thanks!

@ghost ghost closed this as completed Dec 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant