Skip to content

Commit

Permalink
Applying suggested changes from the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Dec 12, 2020
1 parent fe5eac8 commit 5997146
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,18 +1238,20 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
return;
}

// Check that the match doesn't contain other branches that might be excluded by `#[cfg]` or other
// macros
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("=>") {
// The code it self contains another thick arrow "=>"
// -> Either another arm or a comment
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;
}
}

Expand Down

0 comments on commit 5997146

Please sign in to comment.