Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2512341

Browse files
feat: 7125 shorten lint text
1 parent c58d692 commit 2512341

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

clippy_lints/src/loops/single_element_loop.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ pub(super) fn check<'tcx>(
8888
}
8989

9090
if clippy_utils::higher::Range::hir(arg_expression).is_some() {
91+
let range_expr = snippet(cx, arg_expression.span, "?").to_string();
92+
9193
let sugg = snippet(cx, arg_expression.span, "..");
9294
span_lint_and_sugg(
9395
cx,
9496
SINGLE_ELEMENT_LOOP,
9597
arg.span,
96-
"for loop over a single range inside an array, rather than iterating over the elements in the range directly",
98+
format!("This loops only once with {pat_snip} being {range_expr}").as_str(),
9799
"did you mean to iterate over the range instead?",
98100
sugg.to_string(),
99101
Applicability::Unspecified,

tests/ui/single_element_loop.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ LL + dbg!(item);
3232
LL + }
3333
|
3434

35-
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly
35+
error: This loops only once with item being 0..5
3636
--> $DIR/single_element_loop.rs:16:17
3737
|
3838
LL | for item in &[0..5] {
3939
| ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
4040

41-
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly
41+
error: This loops only once with item being 0..5
4242
--> $DIR/single_element_loop.rs:20:17
4343
|
4444
LL | for item in [0..5].iter_mut() {
4545
| ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
4646

47-
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly
47+
error: This loops only once with item being 0..5
4848
--> $DIR/single_element_loop.rs:24:17
4949
|
5050
LL | for item in [0..5] {
5151
| ^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
5252

53-
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly
53+
error: This loops only once with item being 0..5
5454
--> $DIR/single_element_loop.rs:28:17
5555
|
5656
LL | for item in [0..5].into_iter() {

0 commit comments

Comments
 (0)