about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-26 22:37:06 +0000
committerbors <bors@rust-lang.org>2014-11-26 22:37:06 +0000
commitfac5a07679cac21a580badc84b755b8df0f975cf (patch)
treeae15b481ed531e4fae600c41ca41107f6ad3e279 /src/test
parent6faff24ec85744de092a7d7c2378370f65d623bb (diff)
parent9d01db1966a3ab073691eb8e5203e36624b9f992 (diff)
downloadrust-fac5a07679cac21a580badc84b755b8df0f975cf.tar.gz
rust-fac5a07679cac21a580badc84b755b8df0f975cf.zip
auto merge of #19115 : jakub-/rust/issue-19100, r=alexcrichton
...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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-12116.rs3
-rw-r--r--src/test/compile-fail/issue-14221.rs2
-rw-r--r--src/test/compile-fail/lint-uppercase-variables.rs3
-rw-r--r--src/test/run-pass/issue-19100.rs34
4 files changed, 40 insertions, 2 deletions
diff --git a/src/test/compile-fail/issue-12116.rs b/src/test/compile-fail/issue-12116.rs
index 59e29516a74..47907ac2be9 100644
--- a/src/test/compile-fail/issue-12116.rs
+++ b/src/test/compile-fail/issue-12116.rs
@@ -17,7 +17,8 @@ fn tail(source_list: &IntList) -> IntList {
     match source_list {
         &IntList::Cons(val, box ref next_list) => tail(next_list),
         &IntList::Cons(val, box Nil)           => IntList::Cons(val, box Nil),
-        //~^ ERROR: unreachable pattern
+//~^ ERROR unreachable pattern
+//~^^ WARN pattern binding `Nil` is named the same as one of the variants of the type `IntList`
         _                          => panic!()
     }
 }
diff --git a/src/test/compile-fail/issue-14221.rs b/src/test/compile-fail/issue-14221.rs
index c58012dc84c..e79be99a346 100644
--- a/src/test/compile-fail/issue-14221.rs
+++ b/src/test/compile-fail/issue-14221.rs
@@ -17,7 +17,9 @@ pub mod b {
     pub fn key(e: ::E) -> &'static str {
         match e {
             A => "A",
+//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
             B => "B", //~ ERROR: unreachable pattern
+//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
         }
     }
 }
diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs
index 2f840ee0761..eb5c475e7ef 100644
--- a/src/test/compile-fail/lint-uppercase-variables.rs
+++ b/src/test/compile-fail/lint-uppercase-variables.rs
@@ -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);
diff --git a/src/test/run-pass/issue-19100.rs b/src/test/run-pass/issue-19100.rs
new file mode 100644
index 00000000000..cee5c808f99
--- /dev/null
+++ b/src/test/run-pass/issue-19100.rs
@@ -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() {}