about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeSeulArtichaut <leseulartichaut@gmail.com>2020-01-02 00:48:58 +0100
committerLeSeulArtichaut <leseulartichaut@gmail.com>2020-01-02 00:50:52 +0100
commitf474c0084a23207f89bd082b441bfb4701c8c2dc (patch)
treeeb05192ddbab7c70b6df1a670bfeeebe91cb5bce
parent4f639854121261f55863dbf2a88c626abb07247a (diff)
downloadrust-f474c0084a23207f89bd082b441bfb4701c8c2dc.tar.gz
rust-f474c0084a23207f89bd082b441bfb4701c8c2dc.zip
Added test
-rw-r--r--src/test/ui/match/match-same-name-enum-variant.rs33
-rw-r--r--src/test/ui/match/match-same-name-enum-variant.stderr24
2 files changed, 57 insertions, 0 deletions
diff --git a/src/test/ui/match/match-same-name-enum-variant.rs b/src/test/ui/match/match-same-name-enum-variant.rs
new file mode 100644
index 00000000000..d106bf71341
--- /dev/null
+++ b/src/test/ui/match/match-same-name-enum-variant.rs
@@ -0,0 +1,33 @@
+// Test for issue #67776: binding named the same as enum variant
+// should report a warning even when matching against a borrow
+
+// check-pass
+
+#![allow(unused_variables)]
+#![allow(non_snake_case)]
+
+enum Foo {
+    Bar,
+    Baz,
+}
+
+
+fn fn2(e: Foo) {
+    match e {
+        Bar => println!("A"),
+        //~^ WARNING named the same as one of the variants of the type `Foo`
+        Baz => println!("B"),
+        //~^ WARNING named the same as one of the variants of the type `Foo`
+    }
+}
+
+fn fn1(e: &Foo) {
+    match e {
+        Bar => println!("A"),
+        //~^ WARNING named the same as one of the variants of the type `Foo`
+        Baz => println!("B"),
+        //~^ WARNING named the same as one of the variants of the type `Foo`
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/match/match-same-name-enum-variant.stderr b/src/test/ui/match/match-same-name-enum-variant.stderr
new file mode 100644
index 00000000000..cadf5e6cdee
--- /dev/null
+++ b/src/test/ui/match/match-same-name-enum-variant.stderr
@@ -0,0 +1,24 @@
+warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
+  --> $DIR/match-same-name-enum-variant.rs:14:9
+   |
+LL |         Bar => println!("A"),
+   |         ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
+
+warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
+  --> $DIR/match-same-name-enum-variant.rs:16:9
+   |
+LL |         Baz => println!("B"),
+   |         ^^^ help: to match on the variant, qualify the path: `Foo::Baz`
+
+warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
+  --> $DIR/match-same-name-enum-variant.rs:23:9
+   |
+LL |         Bar => println!("A"),
+   |         ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
+
+warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
+  --> $DIR/match-same-name-enum-variant.rs:25:9
+   |
+LL |         Baz => println!("B"),
+   |         ^^^ help: to match on the variant, qualify the path: `Foo::Baz`
+