Remove hack testing for cfg attribute in match_single_binding

This commit is contained in:
Jason Newcomb 2022-02-17 14:16:21 -05:00
parent 8ce2d46cac
commit 8912d659cd
4 changed files with 16 additions and 25 deletions

View File

@ -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);

View File

@ -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");
}

View File

@ -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 {
// =>

View File

@ -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