Skip to content

Commit

Permalink
Ignore desugarings in macro checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 11, 2019
1 parent 5661e59 commit 0499184
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
11 changes: 10 additions & 1 deletion clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/into_iter_on_ref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions tests/ui/into_iter_on_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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
|
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
|
Expand Down Expand Up @@ -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

0 comments on commit 0499184

Please sign in to comment.