about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Hamilton <alex.hamilton@ou.edu>2019-01-29 14:25:40 -0600
committerAlex Hamilton <alex.hamilton@ou.edu>2019-01-29 15:33:04 -0600
commitefaed8e0c0bc67d46a647a0ceb94b4b095ce04db (patch)
tree8df95c6fd74f7cec2f63e250e9e15d62ef591f1b
parentc676578097eb785cc3933ce363a93affc726ff51 (diff)
downloadrust-efaed8e0c0bc67d46a647a0ceb94b4b095ce04db.tar.gz
rust-efaed8e0c0bc67d46a647a0ceb94b4b095ce04db.zip
wildcard_match_arm: lint only enum matches.
-rw-r--r--CHANGELOG.md2
-rw-r--r--clippy_lints/src/lib.rs2
-rw-r--r--clippy_lints/src/matches.rs36
-rw-r--r--tests/ui/wildcard_enum_match_arm.rs (renamed from tests/ui/wildcard_match_arm.rs)8
-rw-r--r--tests/ui/wildcard_enum_match_arm.stderr (renamed from tests/ui/wildcard_match_arm.stderr)8
5 files changed, 32 insertions, 24 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ac88d09a53..71066aadfcb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1028,7 +1028,7 @@ All notable changes to this project will be documented in this file.
 [`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop
 [`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
 [`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
-[`wildcard_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_match_arm
+[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm
 [`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal
 [`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
 [`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index f4ba38496be..52cc2a88da4 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -499,7 +499,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
         indexing_slicing::INDEXING_SLICING,
         inherent_impl::MULTIPLE_INHERENT_IMPL,
         literal_representation::DECIMAL_LITERAL_REPRESENTATION,
-        matches::WILDCARD_MATCH_ARM,
+        matches::WILDCARD_ENUM_MATCH_ARM,
         mem_forget::MEM_FORGET,
         methods::CLONE_ON_REF_PTR,
         methods::OPTION_UNWRAP_USED,
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index 0245b5a1362..e0094b19998 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -187,9 +187,9 @@ declare_clippy_lint! {
     "a match on an Option value instead of using `as_ref()` or `as_mut`"
 }
 
-/// **What it does:** Checks for wildcard matches using `_`.
+/// **What it does:** Checks for wildcard enum matches using `_`.
 ///
-/// **Why is this bad?** New variants added by library updates can be missed.
+/// **Why is this bad?** New enum variants added by library updates can be missed.
 ///
 /// **Known problems:** None.
 ///
@@ -201,9 +201,9 @@ declare_clippy_lint! {
 /// }
 /// ```
 declare_clippy_lint! {
-    pub WILDCARD_MATCH_ARM,
+    pub WILDCARD_ENUM_MATCH_ARM,
     restriction,
-    "a wildcard match arm using `_`"
+    "a wildcard enum match arm using `_`"
 }
 
 #[allow(missing_copy_implementations)]
@@ -219,7 +219,7 @@ impl LintPass for MatchPass {
             MATCH_OVERLAPPING_ARM,
             MATCH_WILD_ERR_ARM,
             MATCH_AS_REF,
-            WILDCARD_MATCH_ARM
+            WILDCARD_ENUM_MATCH_ARM
         )
     }
 
@@ -238,7 +238,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchPass {
             check_match_bool(cx, ex, arms, expr);
             check_overlapping_arms(cx, ex, arms);
             check_wild_err_arm(cx, ex, arms);
-            check_wild_match(cx, arms);
+            check_wild_enum_match(cx, ex, arms);
             check_match_as_ref(cx, ex, arms, expr);
         }
         if let ExprKind::Match(ref ex, ref arms, _) = expr.node {
@@ -463,17 +463,19 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
     }
 }
 
-fn check_wild_match(cx: &LateContext<'_, '_>, arms: &[Arm]) {
-    for arm in arms {
-        if is_wild(&arm.pats[0]) {
-            span_note_and_lint(
-                cx,
-                WILDCARD_MATCH_ARM,
-                arm.pats[0].span,
-                "wildcard match will miss any future added variants.",
-                arm.pats[0].span,
-                "to resolve, match each variant explicitly",
-            );
+fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
+    if cx.tables.expr_ty(ex).is_enum() {
+        for arm in arms {
+            if is_wild(&arm.pats[0]) {
+                span_note_and_lint(
+                    cx,
+                    WILDCARD_ENUM_MATCH_ARM,
+                    arm.pats[0].span,
+                    "wildcard match will miss any future added variants.",
+                    arm.pats[0].span,
+                    "to resolve, match each variant explicitly",
+                );
+            }
         }
     }
 }
diff --git a/tests/ui/wildcard_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs
index 5d3a5ff2a75..58daabf4268 100644
--- a/tests/ui/wildcard_match_arm.rs
+++ b/tests/ui/wildcard_enum_match_arm.rs
@@ -1,4 +1,4 @@
-#![deny(clippy::wildcard_match_arm)]
+#![deny(clippy::wildcard_enum_match_arm)]
 
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
 enum Color {
@@ -33,4 +33,10 @@ fn main() {
         c if c.is_monochrome() => {},
         Color::Rgb(_, _, _) => {},
     };
+    let x: u8 = unimplemented!();
+    match x {
+        0 => {},
+        140 => {},
+        _ => {},
+    };
 }
diff --git a/tests/ui/wildcard_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr
index b78a82f60b5..6319a3f3d46 100644
--- a/tests/ui/wildcard_match_arm.stderr
+++ b/tests/ui/wildcard_enum_match_arm.stderr
@@ -1,14 +1,14 @@
 error: wildcard match will miss any future added variants.
-  --> $DIR/wildcard_match_arm.rs:26:9
+  --> $DIR/wildcard_enum_match_arm.rs:26:9
    |
 LL |         _ => eprintln!("Not red"),
    |         ^
    |
 note: lint level defined here
-  --> $DIR/wildcard_match_arm.rs:1:9
+  --> $DIR/wildcard_enum_match_arm.rs:1:9
    |
-LL | #![deny(clippy::wildcard_match_arm)]
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #![deny(clippy::wildcard_enum_match_arm)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: to resolve, match each variant explicitly
 
 error: aborting due to previous error