1
Fork 0

Warn on pattern bindings that have the same name as a variant

...of the type being matched.

This change will result in a better diagnostic for code like the following:

```rust
enum Enum {
    Foo,
    Bar
}

fn f(x: Enum) {
    match x {
        Foo => (),
        Bar => ()
    }
}
```

which would currently simply fail with an unreachable pattern error
on the 2nd arm.

The user is advised to either use a qualified path in the patterns
or import the variants explicitly into the scope.
This commit is contained in:
Jakub Bukaj 2014-11-20 16:57:36 +01:00
parent 6faff24ec8
commit 5804a30686
6 changed files with 100 additions and 29 deletions

View file

@ -33,7 +33,8 @@ fn main() {
match f.read(&mut buff) {
Ok(cnt) => println!("read this many bytes: {}", cnt),
Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_string()),
//~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file`
//~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file`
//~^^ WARN `EndOfFile` is named the same as one of the variants of the type `std::io::IoErrorKind`
}
test(1);