This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -88,12 +88,14 @@ pub(super) fn check<'tcx>(
88
88
}
89
89
90
90
if clippy_utils:: higher:: Range :: hir ( arg_expression) . is_some ( ) {
91
+ let range_expr = snippet ( cx, arg_expression. span , "?" ) . to_string ( ) ;
92
+
91
93
let sugg = snippet ( cx, arg_expression. span , ".." ) ;
92
94
span_lint_and_sugg (
93
95
cx,
94
96
SINGLE_ELEMENT_LOOP ,
95
97
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 ( ) ,
97
99
"did you mean to iterate over the range instead?" ,
98
100
sugg. to_string ( ) ,
99
101
Applicability :: Unspecified ,
Original file line number Diff line number Diff line change @@ -32,25 +32,25 @@ LL + dbg!(item);
32
32
LL + }
33
33
|
34
34
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
36
36
--> $DIR/single_element_loop.rs:16:17
37
37
|
38
38
LL | for item in &[0..5] {
39
39
| ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
40
40
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
42
42
--> $DIR/single_element_loop.rs:20:17
43
43
|
44
44
LL | for item in [0..5].iter_mut() {
45
45
| ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
46
46
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
48
48
--> $DIR/single_element_loop.rs:24:17
49
49
|
50
50
LL | for item in [0..5] {
51
51
| ^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
52
52
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
54
54
--> $DIR/single_element_loop.rs:28:17
55
55
|
56
56
LL | for item in [0..5].into_iter() {
You can’t perform that action at this time.
0 commit comments