Skip to content

Commit d92070a

Browse files
committed
Auto merge of #10254 - tylerjw:issue_6929, r=Manishearth
needless_range_loop: improve documentation fixes #6929 changelog: [`needless_range_loop`]: improve documentation
2 parents 8fb0041 + 5ed191d commit d92070a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

clippy_lints/src/loops/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ declare_clippy_lint! {
6161
///
6262
/// ### Why is this bad?
6363
/// Just iterating the collection itself makes the intent
64-
/// more clear and is probably faster.
64+
/// more clear and is probably faster because it eliminates
65+
/// the bounds check that is done when indexing.
6566
///
6667
/// ### Example
6768
/// ```rust

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub(super) fn check<'tcx>(
149149
|diag| {
150150
multispan_sugg(
151151
diag,
152-
"consider using an iterator",
152+
"consider using an iterator and enumerate()",
153153
vec![
154154
(pat.span, format!("({}, <item>)", ident.name)),
155155
(

tests/ui/needless_range_loop.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ error: the loop variable `i` is used to index `vec`
4949
LL | for i in 0..vec.len() {
5050
| ^^^^^^^^^^^^
5151
|
52-
help: consider using an iterator
52+
help: consider using an iterator and enumerate()
5353
|
5454
LL | for (i, <item>) in vec.iter().enumerate() {
5555
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
@@ -126,7 +126,7 @@ error: the loop variable `i` is used to index `vec`
126126
LL | for i in 5..vec.len() {
127127
| ^^^^^^^^^^^^
128128
|
129-
help: consider using an iterator
129+
help: consider using an iterator and enumerate()
130130
|
131131
LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
132132
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -137,7 +137,7 @@ error: the loop variable `i` is used to index `vec`
137137
LL | for i in 5..10 {
138138
| ^^^^^
139139
|
140-
help: consider using an iterator
140+
help: consider using an iterator and enumerate()
141141
|
142142
LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
143143
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -148,7 +148,7 @@ error: the loop variable `i` is used to index `vec`
148148
LL | for i in 0..vec.len() {
149149
| ^^^^^^^^^^^^
150150
|
151-
help: consider using an iterator
151+
help: consider using an iterator and enumerate()
152152
|
153153
LL | for (i, <item>) in vec.iter_mut().enumerate() {
154154
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)