diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 3c4f06077d9..950c1043802 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -31,7 +31,7 @@ use std::mem; use crate::syntax::ast; use crate::syntax::source_map::Span; use crate::syntax_pos::BytePos; -use crate::utils::{sugg, sext}; +use crate::utils::{in_macro, sugg, sext}; use crate::utils::usage::mutated_variables; use crate::consts::{constant, Constant}; @@ -1030,6 +1030,10 @@ fn check_for_loop_range<'a, 'tcx>( body: &'tcx Expr, expr: &'tcx Expr, ) { + if in_macro(expr.span) { + return; + } + if let Some(higher::Range { start: Some(start), ref end, diff --git a/mini-macro/src/lib.rs b/mini-macro/src/lib.rs index d326dd7e679..b6405975862 100644 --- a/mini-macro/src/lib.rs +++ b/mini-macro/src/lib.rs @@ -17,5 +17,10 @@ use proc_macro::{TokenStream, quote}; pub fn mini_macro(_: TokenStream) -> TokenStream { quote!( #[allow(unused)] fn needless_take_by_value(s: String) { println!("{}", s.len()); } + #[allow(unused)] fn needless_loop(items: &[u8]) { + for i in 0..items.len() { + println!("{}", items[i]); + } + } ) }