Skip to content

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

Closed
@ptal

Description

@ptal

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'));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions