Skip to content

Commit 543e601

Browse files
committed
fix(clippy): update loop lints to use arg.span
Adapts clippy for fe1a7f7
1 parent fe1a7f7 commit 543e601

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub(super) fn check<'tcx>(
1515
pat: &'tcx Pat<'_>,
1616
arg: &'tcx Expr<'_>,
1717
body: &'tcx Expr<'_>,
18-
expr: &'tcx Expr<'_>,
1918
) {
2019
let pat_span = pat.span;
2120

@@ -43,7 +42,7 @@ pub(super) fn check<'tcx>(
4342
span_lint_and_then(
4443
cx,
4544
FOR_KV_MAP,
46-
expr.span,
45+
arg_span,
4746
&format!("you seem to want to iterate on a map's {}s", kind),
4847
|diag| {
4948
let map = sugg::Sugg::hir(cx, arg, "map");

src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use rustc_hir::Expr;
55
use rustc_lint::LateContext;
66
use rustc_span::sym;
77

8-
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, expr: &Expr<'_>) -> bool {
8+
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
99
if is_trait_method(cx, arg, sym::Iterator) {
1010
span_lint(
1111
cx,
1212
ITER_NEXT_LOOP,
13-
expr.span,
13+
arg.span,
1414
"you are iterating over `Iterator::next()` which is an Option; this will compile but is \
1515
probably not what you want",
1616
);

src/tools/clippy/clippy_lints/src/loops/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -601,15 +601,15 @@ fn check_for_loop<'tcx>(
601601
needless_range_loop::check(cx, pat, arg, body, expr);
602602
explicit_counter_loop::check(cx, pat, arg, body, expr);
603603
}
604-
check_for_loop_arg(cx, pat, arg, expr);
605-
for_kv_map::check(cx, pat, arg, body, expr);
604+
check_for_loop_arg(cx, pat, arg);
605+
for_kv_map::check(cx, pat, arg, body);
606606
mut_range_bound::check(cx, arg, body);
607607
single_element_loop::check(cx, pat, arg, body, expr);
608608
same_item_push::check(cx, pat, arg, body, expr);
609609
manual_flatten::check(cx, pat, arg, body, span);
610610
}
611611

612-
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) {
612+
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
613613
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
614614

615615
if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind {
@@ -622,7 +622,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
622622
explicit_into_iter_loop::check(cx, self_arg, arg);
623623
},
624624
"next" => {
625-
next_loop_linted = iter_next_loop::check(cx, arg, expr);
625+
next_loop_linted = iter_next_loop::check(cx, arg);
626626
},
627627
_ => {},
628628
}

src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(super) fn check<'tcx>(
146146
span_lint_and_then(
147147
cx,
148148
NEEDLESS_RANGE_LOOP,
149-
expr.span,
149+
arg.span,
150150
&format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
151151
|diag| {
152152
multispan_sugg(
@@ -172,7 +172,7 @@ pub(super) fn check<'tcx>(
172172
span_lint_and_then(
173173
cx,
174174
NEEDLESS_RANGE_LOOP,
175-
expr.span,
175+
arg.span,
176176
&format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
177177
|diag| {
178178
multispan_sugg(

0 commit comments

Comments
 (0)