]> git.lizzy.rs Git - rust.git/commitdiff
wildcard_match_arm: add simple ui test.
authorAlex Hamilton <alex.hamilton@ou.edu>
Fri, 25 Jan 2019 16:42:11 +0000 (10:42 -0600)
committerAlex Hamilton <alex.hamilton@ou.edu>
Tue, 29 Jan 2019 21:33:04 +0000 (15:33 -0600)
tests/ui/wildcard_match_arm.rs [new file with mode: 0644]
tests/ui/wildcard_match_arm.stderr [new file with mode: 0644]

diff --git a/tests/ui/wildcard_match_arm.rs b/tests/ui/wildcard_match_arm.rs
new file mode 100644 (file)
index 0000000..26a37c9
--- /dev/null
@@ -0,0 +1,36 @@
+#![deny(clippy::wildcard_match_arm)]
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+enum Color {
+       Red,
+       Green,
+       Blue,
+       Rgb(u8, u8, u8),
+       Cyan,
+}
+
+impl Color {
+       fn is_monochrome(self) -> bool {
+               match self {
+                       Color::Red | Color::Green | Color::Blue => true,
+                       Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
+                       Color::Cyan => false,
+               }
+       }
+}
+
+fn main() {
+       let color = Color::Rgb(0, 0, 127);
+       match color {
+               Color::Red => println!("Red"),
+               _ => eprintln!("Not red"),
+       };
+       match color {
+               Color::Red => {},
+               Color::Green => {},
+               Color::Blue => {},
+               Color::Cyan => {},
+               c if c.is_monochrome() => {},
+               Color::Rgb(_, _, _) => {},
+       };
+}
\ No newline at end of file
diff --git a/tests/ui/wildcard_match_arm.stderr b/tests/ui/wildcard_match_arm.stderr
new file mode 100644 (file)
index 0000000..0d10382
--- /dev/null
@@ -0,0 +1,15 @@
+error: wildcard match will miss any future added variants.
+  --> $DIR/wildcard_match_arm.rs:26:3
+   |
+LL |         _ => eprintln!("Not red"),
+   |         ^
+   |
+note: lint level defined here
+  --> $DIR/wildcard_match_arm.rs:1:9
+   |
+LL | #![deny(clippy::wildcard_match_arm)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: to resolve, match each variant explicitly
+
+error: aborting due to previous error
+