Skip to content

Commit bd6c2df

Browse files
committed
Change explicit_counter_loop's message to reflect original variable name
1 parent c7d4445 commit bd6c2df

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_lints/src/loops.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn check_for_loop<'a, 'tcx>(
777777
check_for_loop_range(cx, pat, arg, body, expr);
778778
check_for_loop_reverse_range(cx, arg, expr);
779779
check_for_loop_arg(cx, pat, arg, expr);
780-
check_for_loop_explicit_counter(cx, arg, body, expr);
780+
check_for_loop_explicit_counter(cx, pat, arg, body, expr);
781781
check_for_loop_over_map_kv(cx, pat, arg, body, expr);
782782
check_for_mut_range_bound(cx, arg, body);
783783
detect_manual_memcpy(cx, pat, arg, body, expr);
@@ -1453,6 +1453,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) {
14531453

14541454
fn check_for_loop_explicit_counter<'a, 'tcx>(
14551455
cx: &LateContext<'a, 'tcx>,
1456+
pat: &'tcx Pat,
14561457
arg: &'tcx Expr,
14571458
body: &'tcx Expr,
14581459
expr: &'tcx Expr,
@@ -1495,8 +1496,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
14951496
expr.span,
14961497
&format!(
14971498
"the variable `{0}` is used as a loop counter. Consider using `for ({0}, \
1498-
item) in {1}.enumerate()` or similar iterators",
1499+
{1}) in {2}.enumerate()` or similar iterators",
14991500
name,
1501+
snippet(cx, pat.span, "_"),
15001502
snippet(cx, arg.span, "_")
15011503
),
15021504
);

tests/ui/explicit_counter_loop.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
1+
error: the variable `_index` is used as a loop counter. Consider using `for (_index, _v) in &vec.enumerate()` or similar iterators
22
--> $DIR/explicit_counter_loop.rs:6:15
33
|
44
LL | for _v in &vec {
55
| ^^^^
66
|
77
= note: `-D clippy::explicit-counter-loop` implied by `-D warnings`
88

9-
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
9+
error: the variable `_index` is used as a loop counter. Consider using `for (_index, _v) in &vec.enumerate()` or similar iterators
1010
--> $DIR/explicit_counter_loop.rs:12:15
1111
|
1212
LL | for _v in &vec {
1313
| ^^^^
1414

15-
error: the variable `count` is used as a loop counter. Consider using `for (count, item) in text.chars().enumerate()` or similar iterators
15+
error: the variable `count` is used as a loop counter. Consider using `for (count, ch) in text.chars().enumerate()` or similar iterators
1616
--> $DIR/explicit_counter_loop.rs:51:19
1717
|
1818
LL | for ch in text.chars() {
1919
| ^^^^^^^^^^^^
2020

21-
error: the variable `count` is used as a loop counter. Consider using `for (count, item) in text.chars().enumerate()` or similar iterators
21+
error: the variable `count` is used as a loop counter. Consider using `for (count, ch) in text.chars().enumerate()` or similar iterators
2222
--> $DIR/explicit_counter_loop.rs:62:19
2323
|
2424
LL | for ch in text.chars() {

0 commit comments

Comments
 (0)