about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <Thibs@debian.com>2020-10-13 11:17:51 +0200
committerThibsG <Thibs@debian.com>2020-10-13 11:31:13 +0200
commite2124086b8107a59129e163aa120dec50add0f77 (patch)
treeba3144a99146684c59f0ddf20fd2697cc6c121a8
parent6bfc19c687f30f05e33028a22bd321204c53bf43 (diff)
downloadrust-e2124086b8107a59129e163aa120dec50add0f77.tar.gz
rust-e2124086b8107a59129e163aa120dec50add0f77.zip
Fix FP in `same_functions_in_if_condition` lint about condition as macro
-rw-r--r--clippy_lints/src/copies.rs6
-rw-r--r--tests/ui/same_functions_in_if_condition.rs12
2 files changed, 16 insertions, 2 deletions
diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs
index 10a64769585..6c969c3ead0 100644
--- a/clippy_lints/src/copies.rs
+++ b/clippy_lints/src/copies.rs
@@ -1,4 +1,4 @@
-use crate::utils::{eq_expr_value, SpanlessEq, SpanlessHash};
+use crate::utils::{eq_expr_value, in_macro, SpanlessEq, SpanlessHash};
 use crate::utils::{get_parent_expr, higher, if_sequence, snippet, span_lint_and_note, span_lint_and_then};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_hir::{Arm, Block, Expr, ExprKind, MatchSource, Pat, PatKind};
@@ -220,6 +220,10 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
     };
 
     let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool {
+        // Do not lint if any expr originates from a macro
+        if in_macro(lhs.span) || in_macro(rhs.span) {
+            return false;
+        }
         // Do not spawn warning if `IFS_SAME_COND` already produced it.
         if eq_expr_value(cx, lhs, rhs) {
             return false;
diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs
index 686867cf5c6..7f28f025790 100644
--- a/tests/ui/same_functions_in_if_condition.rs
+++ b/tests/ui/same_functions_in_if_condition.rs
@@ -77,4 +77,14 @@ fn ifs_same_cond_fn() {
     }
 }
 
-fn main() {}
+fn main() {
+    // macro as condition (see #6168)
+    let os = if cfg!(target_os = "macos") {
+        "macos"
+    } else if cfg!(target_os = "windows") {
+        "windows"
+    } else {
+        "linux"
+    };
+    println!("{}", os);
+}