-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Encourage iter.next() rather than iter.nth(0), which is less readable
- Loading branch information
1 parent
72a2e0e
commit e059583
Showing
7 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![warn(clippy::iter_nth_zero)] | ||
use std::collections::HashSet; | ||
|
||
struct Foo {} | ||
|
||
impl Foo { | ||
fn nth(&self, index: usize) -> usize { | ||
index + 1 | ||
} | ||
} | ||
|
||
fn main() { | ||
let f = Foo {}; | ||
f.nth(0); // lint does not apply here | ||
|
||
let mut s = HashSet::new(); | ||
s.insert(1); | ||
let x = s.iter().nth(0); | ||
|
||
let mut s2 = HashSet::new(); | ||
s2.insert(2); | ||
let mut iter = s2.iter(); | ||
let y = iter.nth(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: called `.nth(0)` on a `std::iter::Iterator`. Calling `.next()` is more readable | ||
--> $DIR/iter_nth_zero.rs:18:13 | ||
| | ||
LL | let x = s.iter().nth(0); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::iter-nth-zero` implied by `-D warnings` | ||
|
||
error: called `.nth(0)` on a `std::iter::Iterator`. Calling `.next()` is more readable | ||
--> $DIR/iter_nth_zero.rs:23:13 | ||
| | ||
LL | let y = iter.nth(0); | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|