]> git.lizzy.rs Git - rust.git/commitdiff
Add more test cases for match_wildcard_for_single_variants
authorVardan Margaryan <v.t.margaryan@gmail.com>
Fri, 15 May 2020 21:19:30 +0000 (00:19 +0300)
committerVardan Margaryan <v.t.margaryan@gmail.com>
Fri, 15 May 2020 21:19:30 +0000 (00:19 +0300)
tests/ui/match_wildcard_for_single_variants.fixed
tests/ui/match_wildcard_for_single_variants.rs
tests/ui/match_wildcard_for_single_variants.stderr

index 5f1a559f5914307e1d860d2e084546a2e4bcebdd..519200977a798d4356e29bf8bea1b55dcce5fa16 100644 (file)
@@ -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, _, _) => {},
+        _ => {},
+    }
 }
index 1159f9e722d71597040bcf0c6732d7d86ce92690..1df917e085c7123a947294226dae591e207e0f3f 100644 (file)
@@ -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, _, _) => {},
+        _ => {},
+    }
 }
index 128dd4808bf7f0797214a837689ebd19e76e957a..82790aa9e80bba14c4c5e652ac67654dc78f3554 100644 (file)
@@ -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