about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-02-17 14:16:21 -0500
committerJason Newcomb <jsnewcomb@pm.me>2022-02-17 14:16:21 -0500
commit8912d659cdc9e1fd787136fe1b52a285f2fc2106 (patch)
treecfe0936d66c05628a4f49ea1fcc6400f634cd049
parent8ce2d46cacc8b91f1d252d52cb38f397ee990435 (diff)
downloadrust-8912d659cdc9e1fd787136fe1b52a285f2fc2106.tar.gz
rust-8912d659cdc9e1fd787136fe1b52a285f2fc2106.zip
Remove hack testing for `cfg` attribute in `match_single_binding`
-rw-r--r--clippy_lints/src/matches/match_single_binding.rs19
-rw-r--r--tests/ui/match_single_binding.fixed8
-rw-r--r--tests/ui/match_single_binding.rs3
-rw-r--r--tests/ui/match_single_binding.stderr11
4 files changed, 16 insertions, 25 deletions
diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs
index 8ae19e03f1a..39fe54648fb 100644
--- a/clippy_lints/src/matches/match_single_binding.rs
+++ b/clippy_lints/src/matches/match_single_binding.rs
@@ -1,5 +1,5 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::source::{indent_of, snippet_block, snippet_opt, snippet_with_applicability};
+use clippy_utils::source::{indent_of, snippet_block, snippet_with_applicability};
 use clippy_utils::sugg::Sugg;
 use clippy_utils::{get_parent_expr, is_refutable, peel_blocks};
 use rustc_errors::Applicability;
@@ -14,23 +14,6 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
         return;
     }
 
-    // HACK:
-    // This is a hack to deal with arms that are excluded by macros like `#[cfg]`. It is only used here
-    // to prevent false positives as there is currently no better way to detect if code was excluded by
-    // a macro. See PR #6435
-    if_chain! {
-        if let Some(match_snippet) = snippet_opt(cx, expr.span);
-        if let Some(arm_snippet) = snippet_opt(cx, arms[0].span);
-        if let Some(ex_snippet) = snippet_opt(cx, ex.span);
-        let rest_snippet = match_snippet.replace(&arm_snippet, "").replace(&ex_snippet, "");
-        if rest_snippet.contains("=>");
-        then {
-            // The code it self contains another thick arrow "=>"
-            // -> Either another arm or a comment
-            return;
-        }
-    }
-
     let matched_vars = ex.span;
     let bind_names = arms[0].pat.span;
     let match_body = peel_blocks(arms[0].body);
diff --git a/tests/ui/match_single_binding.fixed b/tests/ui/match_single_binding.fixed
index b4ec525ada0..b8dc8179f7d 100644
--- a/tests/ui/match_single_binding.fixed
+++ b/tests/ui/match_single_binding.fixed
@@ -106,10 +106,8 @@ fn main() {
         0 => println!("Array index start"),
         _ => println!("Not an array index start"),
     }
-    // False negative
+
+    // Lint
     let x = 1;
-    match x {
-        // =>
-        _ => println!("Not an array index start"),
-    }
+    println!("Not an array index start");
 }
diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs
index e04c4018b98..fe63dcd63f2 100644
--- a/tests/ui/match_single_binding.rs
+++ b/tests/ui/match_single_binding.rs
@@ -118,7 +118,8 @@ fn main() {
         0 => println!("Array index start"),
         _ => println!("Not an array index start"),
     }
-    // False negative
+
+    // Lint
     let x = 1;
     match x {
         // =>
diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr
index 291fa77dc2e..d939291f53c 100644
--- a/tests/ui/match_single_binding.stderr
+++ b/tests/ui/match_single_binding.stderr
@@ -167,5 +167,14 @@ LL +             unwrapped
 LL ~         })
    |
 
-error: aborting due to 11 previous errors
+error: this match could be replaced by its body itself
+  --> $DIR/match_single_binding.rs:124:5
+   |
+LL | /     match x {
+LL | |         // =>
+LL | |         _ => println!("Not an array index start"),
+LL | |     }
+   | |_____^ help: consider using the match body instead: `println!("Not an array index start");`
+
+error: aborting due to 12 previous errors