mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
needless_range_loop: improve documentation
This commit is contained in:
parent
96c28d1f69
commit
4d266d31de
3 changed files with 7 additions and 6 deletions
|
@ -61,7 +61,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
/// Just iterating the collection itself makes the intent
|
/// 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
|
/// ### Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
|
@ -149,7 +149,7 @@ pub(super) fn check<'tcx>(
|
||||||
|diag| {
|
|diag| {
|
||||||
multispan_sugg(
|
multispan_sugg(
|
||||||
diag,
|
diag,
|
||||||
"consider using an iterator",
|
"consider using an iterator and enumerate",
|
||||||
vec![
|
vec![
|
||||||
(pat.span, format!("({}, <item>)", ident.name)),
|
(pat.span, format!("({}, <item>)", ident.name)),
|
||||||
(
|
(
|
||||||
|
|
|
@ -49,7 +49,7 @@ error: the loop variable `i` is used to index `vec`
|
||||||
LL | for i in 0..vec.len() {
|
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() {
|
LL | for (i, <item>) in vec.iter().enumerate() {
|
||||||
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -126,7 +126,7 @@ error: the loop variable `i` is used to index `vec`
|
||||||
LL | for i in 5..vec.len() {
|
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) {
|
LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
|
||||||
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -137,7 +137,7 @@ error: the loop variable `i` is used to index `vec`
|
||||||
LL | for i in 5..10 {
|
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) {
|
LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
|
||||||
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -148,7 +148,7 @@ error: the loop variable `i` is used to index `vec`
|
||||||
LL | for i in 0..vec.len() {
|
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() {
|
LL | for (i, <item>) in vec.iter_mut().enumerate() {
|
||||||
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Reference in a new issue