Skip to content

Commit adbaa85

Browse files
authored
Merge pull request #3330 from shssoichiro/3309-goblin-ice
Resolve ICE in needless range loop lint
2 parents f40c4fa + 4b68c96 commit adbaa85

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clippy_lints/src/loops.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::mem;
3131
use crate::syntax::ast;
3232
use crate::syntax::source_map::Span;
3333
use crate::syntax_pos::BytePos;
34-
use crate::utils::{sugg, sext};
34+
use crate::utils::{in_macro, sugg, sext};
3535
use crate::utils::usage::mutated_variables;
3636
use crate::consts::{constant, Constant};
3737

@@ -1030,6 +1030,10 @@ fn check_for_loop_range<'a, 'tcx>(
10301030
body: &'tcx Expr,
10311031
expr: &'tcx Expr,
10321032
) {
1033+
if in_macro(expr.span) {
1034+
return;
1035+
}
1036+
10331037
if let Some(higher::Range {
10341038
start: Some(start),
10351039
ref end,

mini-macro/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ use proc_macro::{TokenStream, quote};
1717
pub fn mini_macro(_: TokenStream) -> TokenStream {
1818
quote!(
1919
#[allow(unused)] fn needless_take_by_value(s: String) { println!("{}", s.len()); }
20+
#[allow(unused)] fn needless_loop(items: &[u8]) {
21+
for i in 0..items.len() {
22+
println!("{}", items[i]);
23+
}
24+
}
2025
)
2126
}

0 commit comments

Comments
 (0)