From 223e23a5ce59b6328765a09e2d7bc95243982d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Woim=C3=A9e?= Date: Sun, 1 Sep 2019 19:59:14 +0200 Subject: [PATCH] fix misleading doc for explicit_counter_loop lint --- clippy_lints/src/loops.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 0ad7c26f849..581ed0744fe 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -298,26 +298,25 @@ declare_clippy_lint! { /// **What it does:** Checks `for` loops over slices with an explicit counter /// and suggests the use of `.enumerate()`. /// - /// **Why is it bad?** Not only is the version using `.enumerate()` more - /// readable, the compiler is able to remove bounds checks which can lead to - /// faster code in some instances. + /// **Why is it bad?** Using `.enumerate()` makes the intent more clear, + /// declutters the code and may be faster in some instances. /// /// **Known problems:** None. /// /// **Example:** /// ```rust /// # let v = vec![1]; - /// # fn foo(bar: usize) {} /// # fn bar(bar: usize, baz: usize) {} - /// for i in 0..v.len() { foo(v[i]); } - /// for i in 0..v.len() { bar(i, v[i]); } + /// let mut i = 0; + /// for item in &v { + /// bar(i, *item); + /// i += 1; + /// } /// ``` /// Could be written as /// ```rust /// # let v = vec![1]; - /// # fn foo(bar: usize) {} /// # fn bar(bar: usize, baz: usize) {} - /// for item in &v { foo(*item); } /// for (i, item) in v.iter().enumerate() { bar(i, *item); } /// ``` pub EXPLICIT_COUNTER_LOOP,