Skip to content

Commit 28a39e9

Browse files
committed
Auto merge of rust-lang#4165 - BO41:needless_range_loop, r=phansch
Add example to needless_range_loop adds a "could be written as" example btw, is it correct that the lint triggers even if the index is used not just for getting the values by index? So that I have to add `.iter().enumerate()` to still get an index? changelog: none
2 parents 4b45bd9 + dd007e4 commit 28a39e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

clippy_lints/src/loops.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ declare_clippy_lint! {
6161
/// **Known problems:** None.
6262
///
6363
/// **Example:**
64-
/// ```ignore
64+
/// ```rust
65+
/// let vec = vec!['a', 'b', 'c'];
6566
/// for i in 0..vec.len() {
6667
/// println!("{}", vec[i]);
6768
/// }
6869
/// ```
70+
/// Could be written as:
71+
/// ```rust
72+
/// let vec = vec!['a', 'b', 'c'];
73+
/// for i in vec {
74+
/// println!("{}", i);
75+
/// }
76+
/// ```
6977
pub NEEDLESS_RANGE_LOOP,
7078
style,
7179
"for-looping over a range of indices where an iterator over items would do"

0 commit comments

Comments
 (0)