Skip to content

needless_range_loop: improve documentation #10254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clippy_lints/src/loops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ declare_clippy_lint! {
///
/// ### Why is this bad?
/// Just iterating the collection itself makes the intent
/// more clear and is probably faster.
/// more clear and is probably faster because it eliminates
/// the bounds check that is done when indexing.
///
/// ### Example
/// ```rust
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/needless_range_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub(super) fn check<'tcx>(
|diag| {
multispan_sugg(
diag,
"consider using an iterator",
"consider using an iterator and enumerate()",
vec![
(pat.span, format!("({}, <item>)", ident.name)),
(
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/needless_range_loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ error: the loop variable `i` is used to index `vec`
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
|
help: consider using an iterator
help: consider using an iterator and enumerate()
|
LL | for (i, <item>) in vec.iter().enumerate() {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -126,7 +126,7 @@ error: the loop variable `i` is used to index `vec`
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
|
help: consider using an iterator
help: consider using an iterator and enumerate()
|
LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -137,7 +137,7 @@ error: the loop variable `i` is used to index `vec`
LL | for i in 5..10 {
| ^^^^^
|
help: consider using an iterator
help: consider using an iterator and enumerate()
|
LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -148,7 +148,7 @@ error: the loop variable `i` is used to index `vec`
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
|
help: consider using an iterator
help: consider using an iterator and enumerate()
|
LL | for (i, <item>) in vec.iter_mut().enumerate() {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down