From bd6c2df066ce2bd3296faf537b9fbb9a1b967d73 Mon Sep 17 00:00:00 2001 From: rail <12975677+rail-rain@users.noreply.github.com> Date: Sat, 23 Mar 2019 15:30:17 +0900 Subject: [PATCH] Change explicit_counter_loop's message to reflect original variable name --- clippy_lints/src/loops.rs | 6 ++++-- tests/ui/explicit_counter_loop.stderr | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 0016625631c7..d88f3e6782f5 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -777,7 +777,7 @@ fn check_for_loop<'a, 'tcx>( check_for_loop_range(cx, pat, arg, body, expr); check_for_loop_reverse_range(cx, arg, expr); check_for_loop_arg(cx, pat, arg, expr); - check_for_loop_explicit_counter(cx, arg, body, expr); + check_for_loop_explicit_counter(cx, pat, arg, body, expr); check_for_loop_over_map_kv(cx, pat, arg, body, expr); check_for_mut_range_bound(cx, arg, body); detect_manual_memcpy(cx, pat, arg, body, expr); @@ -1453,6 +1453,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) { fn check_for_loop_explicit_counter<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, + pat: &'tcx Pat, arg: &'tcx Expr, body: &'tcx Expr, expr: &'tcx Expr, @@ -1495,8 +1496,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>( expr.span, &format!( "the variable `{0}` is used as a loop counter. Consider using `for ({0}, \ - item) in {1}.enumerate()` or similar iterators", + {1}) in {2}.enumerate()` or similar iterators", name, + snippet(cx, pat.span, "_"), snippet(cx, arg.span, "_") ), ); diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index b1cfb31432f2..84ca0db8388b 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -1,4 +1,4 @@ -error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators +error: the variable `_index` is used as a loop counter. Consider using `for (_index, _v) in &vec.enumerate()` or similar iterators --> $DIR/explicit_counter_loop.rs:6:15 | LL | for _v in &vec { @@ -6,19 +6,19 @@ LL | for _v in &vec { | = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` -error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators +error: the variable `_index` is used as a loop counter. Consider using `for (_index, _v) in &vec.enumerate()` or similar iterators --> $DIR/explicit_counter_loop.rs:12:15 | LL | for _v in &vec { | ^^^^ -error: the variable `count` is used as a loop counter. Consider using `for (count, item) in text.chars().enumerate()` or similar iterators +error: the variable `count` is used as a loop counter. Consider using `for (count, ch) in text.chars().enumerate()` or similar iterators --> $DIR/explicit_counter_loop.rs:51:19 | LL | for ch in text.chars() { | ^^^^^^^^^^^^ -error: the variable `count` is used as a loop counter. Consider using `for (count, item) in text.chars().enumerate()` or similar iterators +error: the variable `count` is used as a loop counter. Consider using `for (count, ch) in text.chars().enumerate()` or similar iterators --> $DIR/explicit_counter_loop.rs:62:19 | LL | for ch in text.chars() {