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>(
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 ,
Original file line number Diff line number Diff line change @@ -32,25 +32,25 @@ LL + dbg!(item);
3232LL + }
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 |
3838LL | 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 |
4444LL | 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 |
5050LL | 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 |
5656LL | for item in [0..5].into_iter() {
You can’t perform that action at this time.
0 commit comments