Skip to content

Commit 8912d65

Browse files
committed
Remove hack testing for cfg attribute in match_single_binding
1 parent 8ce2d46 commit 8912d65

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

clippy_lints/src/matches/match_single_binding.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::{indent_of, snippet_block, snippet_opt, snippet_with_applicability};
2+
use clippy_utils::source::{indent_of, snippet_block, snippet_with_applicability};
33
use clippy_utils::sugg::Sugg;
44
use clippy_utils::{get_parent_expr, is_refutable, peel_blocks};
55
use rustc_errors::Applicability;
@@ -14,23 +14,6 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
1414
return;
1515
}
1616

17-
// HACK:
18-
// This is a hack to deal with arms that are excluded by macros like `#[cfg]`. It is only used here
19-
// to prevent false positives as there is currently no better way to detect if code was excluded by
20-
// a macro. See PR #6435
21-
if_chain! {
22-
if let Some(match_snippet) = snippet_opt(cx, expr.span);
23-
if let Some(arm_snippet) = snippet_opt(cx, arms[0].span);
24-
if let Some(ex_snippet) = snippet_opt(cx, ex.span);
25-
let rest_snippet = match_snippet.replace(&arm_snippet, "").replace(&ex_snippet, "");
26-
if rest_snippet.contains("=>");
27-
then {
28-
// The code it self contains another thick arrow "=>"
29-
// -> Either another arm or a comment
30-
return;
31-
}
32-
}
33-
3417
let matched_vars = ex.span;
3518
let bind_names = arms[0].pat.span;
3619
let match_body = peel_blocks(arms[0].body);

tests/ui/match_single_binding.fixed

+3-5
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ fn main() {
106106
0 => println!("Array index start"),
107107
_ => println!("Not an array index start"),
108108
}
109-
// False negative
109+
110+
// Lint
110111
let x = 1;
111-
match x {
112-
// =>
113-
_ => println!("Not an array index start"),
114-
}
112+
println!("Not an array index start");
115113
}

tests/ui/match_single_binding.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ fn main() {
118118
0 => println!("Array index start"),
119119
_ => println!("Not an array index start"),
120120
}
121-
// False negative
121+
122+
// Lint
122123
let x = 1;
123124
match x {
124125
// =>

tests/ui/match_single_binding.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,14 @@ LL + unwrapped
167167
LL ~ })
168168
|
169169

170-
error: aborting due to 11 previous errors
170+
error: this match could be replaced by its body itself
171+
--> $DIR/match_single_binding.rs:124:5
172+
|
173+
LL | / match x {
174+
LL | | // =>
175+
LL | | _ => println!("Not an array index start"),
176+
LL | | }
177+
| |_____^ help: consider using the match body instead: `println!("Not an array index start");`
178+
179+
error: aborting due to 12 previous errors
171180

0 commit comments

Comments
 (0)