Skip to content

Commit 750eba5

Browse files
committed
Ignore desugarings in macro checks
1 parent 7ea5e20 commit 750eba5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_errors::Applicability;
4141
use syntax::ast::{self, LitKind};
4242
use syntax::attr;
4343
use syntax::source_map::{Span, DUMMY_SP};
44+
use syntax::ext::hygiene::ExpnFormat;
4445
use syntax::symbol::{keywords, Symbol};
4546

4647
use crate::reexport::*;
@@ -90,7 +91,15 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
9091

9192
/// Returns `true` if this `expn_info` was expanded by any macro.
9293
pub fn in_macro(span: Span) -> bool {
93-
span.ctxt().outer().expn_info().is_some()
94+
if let Some(info) = span.ctxt().outer().expn_info() {
95+
if let ExpnFormat::CompilerDesugaring(..) = info.format {
96+
false
97+
} else {
98+
true
99+
}
100+
} else {
101+
false
102+
}
94103
}
95104

96105
// If the snippet is empty, it's an attribute that was inserted during macro

tests/ui/into_iter_on_ref.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
for _ in &[1, 2, 3] {}
1111
for _ in vec![X, X] {}
1212
for _ in &vec![X, X] {}
13-
for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
13+
for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
1414

1515
let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
1616
let _ = vec![1, 2, 3].into_iter();

tests/ui/into_iter_on_ref.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
error: this .into_iter() call is equivalent to .iter() and will not move the array
2-
--> $DIR/into_iter_on_ref.rs:15:23
2+
--> $DIR/into_iter_on_ref.rs:13:24
33
|
4-
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
5-
| ^^^^^^^^^ help: call directly: `iter`
4+
LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
5+
| ^^^^^^^^^ help: call directly: `iter`
66
|
77
note: lint level defined here
88
--> $DIR/into_iter_on_ref.rs:4:9
99
|
1010
LL | #![deny(clippy::into_iter_on_array)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13+
error: this .into_iter() call is equivalent to .iter() and will not move the array
14+
--> $DIR/into_iter_on_ref.rs:15:23
15+
|
16+
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
17+
| ^^^^^^^^^ help: call directly: `iter`
18+
1319
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
1420
--> $DIR/into_iter_on_ref.rs:17:30
1521
|
@@ -168,5 +174,5 @@ error: this .into_iter() call is equivalent to .iter() and will not move the Pat
168174
LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
169175
| ^^^^^^^^^ help: call directly: `iter`
170176

171-
error: aborting due to 27 previous errors
177+
error: aborting due to 28 previous errors
172178

0 commit comments

Comments
 (0)