about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-05-10 23:19:35 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-05-10 23:40:42 -0700
commit049918420150fb42a7b774c1f4680ee7ab7f7627 (patch)
treefa7979dd3a8bdfcbbd505bfaf66a78cb835c7144
parent5661e5947f20030cf6f5d6c5715e81253fabd1a5 (diff)
downloadrust-049918420150fb42a7b774c1f4680ee7ab7f7627.tar.gz
rust-049918420150fb42a7b774c1f4680ee7ab7f7627.zip
Ignore desugarings in macro checks
-rw-r--r--clippy_lints/src/utils/mod.rs11
-rw-r--r--tests/ui/into_iter_on_ref.fixed2
-rw-r--r--tests/ui/into_iter_on_ref.stderr14
3 files changed, 21 insertions, 6 deletions
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index 56837109877..7ebaeb0951f 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -40,6 +40,7 @@ use rustc_data_structures::sync::Lrc;
 use rustc_errors::Applicability;
 use syntax::ast::{self, LitKind};
 use syntax::attr;
+use syntax::ext::hygiene::ExpnFormat;
 use syntax::source_map::{Span, DUMMY_SP};
 use syntax::symbol::{keywords, Symbol};
 
@@ -90,7 +91,15 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
 
 /// Returns `true` if this `expn_info` was expanded by any macro.
 pub fn in_macro(span: Span) -> bool {
-    span.ctxt().outer().expn_info().is_some()
+    if let Some(info) = span.ctxt().outer().expn_info() {
+        if let ExpnFormat::CompilerDesugaring(..) = info.format {
+            false
+        } else {
+            true
+        }
+    } else {
+        false
+    }
 }
 
 // If the snippet is empty, it's an attribute that was inserted during macro
diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed
index 659fd56f9a9..f5342be631b 100644
--- a/tests/ui/into_iter_on_ref.fixed
+++ b/tests/ui/into_iter_on_ref.fixed
@@ -10,7 +10,7 @@ fn main() {
     for _ in &[1, 2, 3] {}
     for _ in vec![X, X] {}
     for _ in &vec![X, X] {}
-    for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
+    for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
 
     let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
     let _ = vec![1, 2, 3].into_iter();
diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr
index c3e5c85618b..931e4880f93 100644
--- a/tests/ui/into_iter_on_ref.stderr
+++ b/tests/ui/into_iter_on_ref.stderr
@@ -1,8 +1,8 @@
 error: this .into_iter() call is equivalent to .iter() and will not move the array
-  --> $DIR/into_iter_on_ref.rs:15:23
+  --> $DIR/into_iter_on_ref.rs:13:24
    |
-LL |     let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
-   |                       ^^^^^^^^^ help: call directly: `iter`
+LL |     for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
+   |                        ^^^^^^^^^ help: call directly: `iter`
    |
 note: lint level defined here
   --> $DIR/into_iter_on_ref.rs:4:9
@@ -10,6 +10,12 @@ note: lint level defined here
 LL | #![deny(clippy::into_iter_on_array)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+error: this .into_iter() call is equivalent to .iter() and will not move the array
+  --> $DIR/into_iter_on_ref.rs:15:23
+   |
+LL |     let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
+   |                       ^^^^^^^^^ help: call directly: `iter`
+
 error: this .into_iter() call is equivalent to .iter() and will not move the Vec
   --> $DIR/into_iter_on_ref.rs:17:30
    |
@@ -168,5 +174,5 @@ error: this .into_iter() call is equivalent to .iter() and will not move the Pat
 LL |     let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
    |                                               ^^^^^^^^^ help: call directly: `iter`
 
-error: aborting due to 27 previous errors
+error: aborting due to 28 previous errors