Ignore desugarings in macro checks

This commit is contained in:
Manish Goregaokar 2019-05-10 23:19:35 -07:00
parent 5661e5947f
commit 0499184201
3 changed files with 21 additions and 6 deletions

View file

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

View file

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

View file

@ -1,7 +1,7 @@
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()
LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
| ^^^^^^^^^ help: call directly: `iter`
|
note: lint level defined here
@ -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