mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
fix misleading doc for explicit_counter_loop lint
This commit is contained in:
parent
a3fcaee562
commit
223e23a5ce
1 changed files with 7 additions and 8 deletions
|
@ -298,26 +298,25 @@ declare_clippy_lint! {
|
||||||
/// **What it does:** Checks `for` loops over slices with an explicit counter
|
/// **What it does:** Checks `for` loops over slices with an explicit counter
|
||||||
/// and suggests the use of `.enumerate()`.
|
/// and suggests the use of `.enumerate()`.
|
||||||
///
|
///
|
||||||
/// **Why is it bad?** Not only is the version using `.enumerate()` more
|
/// **Why is it bad?** Using `.enumerate()` makes the intent more clear,
|
||||||
/// readable, the compiler is able to remove bounds checks which can lead to
|
/// declutters the code and may be faster in some instances.
|
||||||
/// faster code in some instances.
|
|
||||||
///
|
///
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # let v = vec![1];
|
/// # let v = vec![1];
|
||||||
/// # fn foo(bar: usize) {}
|
|
||||||
/// # fn bar(bar: usize, baz: usize) {}
|
/// # fn bar(bar: usize, baz: usize) {}
|
||||||
/// for i in 0..v.len() { foo(v[i]); }
|
/// let mut i = 0;
|
||||||
/// for i in 0..v.len() { bar(i, v[i]); }
|
/// for item in &v {
|
||||||
|
/// bar(i, *item);
|
||||||
|
/// i += 1;
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// Could be written as
|
/// Could be written as
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # let v = vec![1];
|
/// # let v = vec![1];
|
||||||
/// # fn foo(bar: usize) {}
|
|
||||||
/// # fn bar(bar: usize, baz: usize) {}
|
/// # fn bar(bar: usize, baz: usize) {}
|
||||||
/// for item in &v { foo(*item); }
|
|
||||||
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
|
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
|
||||||
/// ```
|
/// ```
|
||||||
pub EXPLICIT_COUNTER_LOOP,
|
pub EXPLICIT_COUNTER_LOOP,
|
||||||
|
|
Loading…
Reference in a new issue