about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVardan Margaryan <v.t.margaryan@gmail.com>2020-05-16 00:19:30 +0300
committerVardan Margaryan <v.t.margaryan@gmail.com>2020-05-16 00:19:30 +0300
commitd90625385e8ed0a9030e3ab2ea0990fce39c28bf (patch)
tree4f0bcc721939cb9cf1e163b645be6539e05c5b79
parent2620d2449da851171773f7bec1396af11babe278 (diff)
downloadrust-d90625385e8ed0a9030e3ab2ea0990fce39c28bf.tar.gz
rust-d90625385e8ed0a9030e3ab2ea0990fce39c28bf.zip
Add more test cases for match_wildcard_for_single_variants
-rw-r--r--tests/ui/match_wildcard_for_single_variants.fixed43
-rw-r--r--tests/ui/match_wildcard_for_single_variants.rs43
-rw-r--r--tests/ui/match_wildcard_for_single_variants.stderr22
3 files changed, 104 insertions, 4 deletions
diff --git a/tests/ui/match_wildcard_for_single_variants.fixed b/tests/ui/match_wildcard_for_single_variants.fixed
index 5f1a559f591..519200977a7 100644
--- a/tests/ui/match_wildcard_for_single_variants.fixed
+++ b/tests/ui/match_wildcard_for_single_variants.fixed
@@ -9,10 +9,51 @@ enum Foo {
     C,
 }
 
+enum Color {
+    Red,
+    Green,
+    Blue,
+    Rgb(u8, u8, u8),
+}
+
 fn main() {
-    match Foo::A {
+    let f = Foo::A;
+    match f {
         Foo::A => {},
         Foo::B => {},
         Foo::C => {},
     }
+
+    let color = Color::Red;
+
+    // check exhaustive bindings
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(_r, _g, _b) => {},
+        Color::Blue => {},
+    }
+
+    // check exhaustive wild
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(..) => {},
+        Color::Blue => {},
+    }
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(_, _, _) => {},
+        Color::Blue => {},
+    }
+
+    // shouldn't lint as there is one missing variant
+    // and one that isn't exhaustively covered
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(255, _, _) => {},
+        _ => {},
+    }
 }
diff --git a/tests/ui/match_wildcard_for_single_variants.rs b/tests/ui/match_wildcard_for_single_variants.rs
index 1159f9e722d..1df917e085c 100644
--- a/tests/ui/match_wildcard_for_single_variants.rs
+++ b/tests/ui/match_wildcard_for_single_variants.rs
@@ -9,10 +9,51 @@ enum Foo {
     C,
 }
 
+enum Color {
+    Red,
+    Green,
+    Blue,
+    Rgb(u8, u8, u8),
+}
+
 fn main() {
-    match Foo::A {
+    let f = Foo::A;
+    match f {
         Foo::A => {},
         Foo::B => {},
         _ => {},
     }
+
+    let color = Color::Red;
+
+    // check exhaustive bindings
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(_r, _g, _b) => {},
+        _ => {},
+    }
+
+    // check exhaustive wild
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(..) => {},
+        _ => {},
+    }
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(_, _, _) => {},
+        _ => {},
+    }
+
+    // shouldn't lint as there is one missing variant
+    // and one that isn't exhaustively covered
+    match color {
+        Color::Red => {},
+        Color::Green => {},
+        Color::Rgb(255, _, _) => {},
+        _ => {},
+    }
 }
diff --git a/tests/ui/match_wildcard_for_single_variants.stderr b/tests/ui/match_wildcard_for_single_variants.stderr
index 128dd4808bf..82790aa9e80 100644
--- a/tests/ui/match_wildcard_for_single_variants.stderr
+++ b/tests/ui/match_wildcard_for_single_variants.stderr
@@ -1,10 +1,28 @@
 error: wildcard match will miss any future added variants
-  --> $DIR/match_wildcard_for_single_variants.rs:16:9
+  --> $DIR/match_wildcard_for_single_variants.rs:24:9
    |
 LL |         _ => {},
    |         ^ help: try this: `Foo::C`
    |
    = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings`
 
-error: aborting due to previous error
+error: wildcard match will miss any future added variants
+  --> $DIR/match_wildcard_for_single_variants.rs:34:9
+   |
+LL |         _ => {},
+   |         ^ help: try this: `Color::Blue`
+
+error: wildcard match will miss any future added variants
+  --> $DIR/match_wildcard_for_single_variants.rs:42:9
+   |
+LL |         _ => {},
+   |         ^ help: try this: `Color::Blue`
+
+error: wildcard match will miss any future added variants
+  --> $DIR/match_wildcard_for_single_variants.rs:48:9
+   |
+LL |         _ => {},
+   |         ^ help: try this: `Color::Blue`
+
+error: aborting due to 4 previous errors