-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #3901 - rail-rain:issue_1670, r=flip1995
Fix `explicit_counter_loop` suggestion #1670 This code seems to me to work, but I have two question. * Because range expression desugared in hir, `Sugg::hir` doesn't add parenthesis to range expression. Which function is better to check range do you think, `check_for_loop_explicit_counter` or `hir_from_snippet`? * Do you think we need to distinguish between range expression and struct expression that creates `std::ops::Range*`?
- Loading branch information
Showing
3 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
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. | ||
--> $DIR/explicit_counter_loop.rs:6:15 | ||
| | ||
LL | for _v in &vec { | ||
| ^^^^ | ||
| ^^^^ help: consider using: `for (_index, _v) in (&vec).enumerate()` | ||
| | ||
= 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. | ||
--> $DIR/explicit_counter_loop.rs:12:15 | ||
| | ||
LL | for _v in &vec { | ||
| ^^^^ | ||
| ^^^^ help: consider using: `for (_index, _v) in (&vec).enumerate()` | ||
|
||
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. | ||
--> $DIR/explicit_counter_loop.rs:51:19 | ||
| | ||
LL | for ch in text.chars() { | ||
| ^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` | ||
|
||
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. | ||
--> $DIR/explicit_counter_loop.rs:62:19 | ||
| | ||
LL | for ch in text.chars() { | ||
| ^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` | ||
|
||
error: aborting due to 4 previous errors | ||
error: the variable `count` is used as a loop counter. | ||
--> $DIR/explicit_counter_loop.rs:120:19 | ||
| | ||
LL | for _i in 3..10 { | ||
| ^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()` | ||
|
||
error: aborting due to 5 previous errors | ||
|