Skip to content

Commit 1f99937

Browse files
committed
Auto merge of #4482 - awoimbee:doc_explicit_counter_loop, r=flip1995
fix misleading doc for explicit_counter_loop lint changelog: replace misleading examples for explicit_counter_loop & more concise `Why is it bad?` section This fixes #4472
2 parents 6dcdd46 + 223e23a commit 1f99937

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

clippy_lints/src/loops.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,25 @@ declare_clippy_lint! {
298298
/// **What it does:** Checks `for` loops over slices with an explicit counter
299299
/// and suggests the use of `.enumerate()`.
300300
///
301-
/// **Why is it bad?** Not only is the version using `.enumerate()` more
302-
/// readable, the compiler is able to remove bounds checks which can lead to
303-
/// faster code in some instances.
301+
/// **Why is it bad?** Using `.enumerate()` makes the intent more clear,
302+
/// declutters the code and may be faster in some instances.
304303
///
305304
/// **Known problems:** None.
306305
///
307306
/// **Example:**
308307
/// ```rust
309308
/// # let v = vec![1];
310-
/// # fn foo(bar: usize) {}
311309
/// # fn bar(bar: usize, baz: usize) {}
312-
/// for i in 0..v.len() { foo(v[i]); }
313-
/// for i in 0..v.len() { bar(i, v[i]); }
310+
/// let mut i = 0;
311+
/// for item in &v {
312+
/// bar(i, *item);
313+
/// i += 1;
314+
/// }
314315
/// ```
315316
/// Could be written as
316317
/// ```rust
317318
/// # let v = vec![1];
318-
/// # fn foo(bar: usize) {}
319319
/// # fn bar(bar: usize, baz: usize) {}
320-
/// for item in &v { foo(*item); }
321320
/// for (i, item) in v.iter().enumerate() { bar(i, *item); }
322321
/// ```
323322
pub EXPLICIT_COUNTER_LOOP,

0 commit comments

Comments
 (0)