-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Jakub Bukaj
committed
Nov 26, 2014
1 parent
6faff24
commit 5804a30
Showing
6 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,5 +145,6 @@ register_diagnostics!( | |
E0166, | ||
E0167, | ||
E0168, | ||
E0169 | ||
E0169, | ||
E0170 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
enum Foo { | ||
Bar, | ||
Baz | ||
} | ||
|
||
impl Foo { | ||
fn foo(&self) { | ||
match self { | ||
& | ||
Bar if true | ||
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
//~^^ HELP to match on a variant, consider making the path in the pattern qualified: `Foo::Bar` | ||
=> println!("bar"), | ||
& | ||
Baz if false | ||
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
//~^^ HELP to match on a variant, consider making the path in the pattern qualified: `Foo::Baz` | ||
=> println!("baz"), | ||
_ => () | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |