forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#5843 - dima74:iter_skip_next.add-suggestion, …
…r=phansch Add suggestion for `iter_skip_next` lint changelog: Add suggestion for [`iter_skip_next`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next) lint
- Loading branch information
Showing
4 changed files
with
48 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// run-rustfix | ||
// aux-build:option_helpers.rs | ||
|
||
#![warn(clippy::iter_skip_next)] | ||
#![allow(clippy::blacklisted_name)] | ||
#![allow(clippy::iter_nth)] | ||
|
||
extern crate option_helpers; | ||
|
||
use option_helpers::IteratorFalsePositives; | ||
|
||
/// Checks implementation of `ITER_SKIP_NEXT` lint | ||
fn main() { | ||
let some_vec = vec![0, 1, 2, 3]; | ||
let _ = some_vec.iter().nth(42); | ||
let _ = some_vec.iter().cycle().nth(42); | ||
let _ = (1..10).nth(10); | ||
let _ = &some_vec[..].iter().nth(3); | ||
let foo = IteratorFalsePositives { foo: 0 }; | ||
let _ = foo.skip(42).next(); | ||
let _ = foo.filter().skip(42).next(); | ||
} |
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 |
---|---|---|
@@ -1,35 +1,28 @@ | ||
error: called `skip(x).next()` on an iterator | ||
--> $DIR/iter_skip_next.rs:13:13 | ||
--> $DIR/iter_skip_next.rs:15:28 | ||
| | ||
LL | let _ = some_vec.iter().skip(42).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` | ||
| | ||
= note: `-D clippy::iter-skip-next` implied by `-D warnings` | ||
= help: this is more succinctly expressed by calling `nth(x)` | ||
|
||
error: called `skip(x).next()` on an iterator | ||
--> $DIR/iter_skip_next.rs:14:13 | ||
--> $DIR/iter_skip_next.rs:16:36 | ||
| | ||
LL | let _ = some_vec.iter().cycle().skip(42).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: this is more succinctly expressed by calling `nth(x)` | ||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` | ||
|
||
error: called `skip(x).next()` on an iterator | ||
--> $DIR/iter_skip_next.rs:15:13 | ||
--> $DIR/iter_skip_next.rs:17:20 | ||
| | ||
LL | let _ = (1..10).skip(10).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: this is more succinctly expressed by calling `nth(x)` | ||
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` | ||
|
||
error: called `skip(x).next()` on an iterator | ||
--> $DIR/iter_skip_next.rs:16:14 | ||
--> $DIR/iter_skip_next.rs:18:33 | ||
| | ||
LL | let _ = &some_vec[..].iter().skip(3).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: this is more succinctly expressed by calling `nth(x)` | ||
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)` | ||
|
||
error: aborting due to 4 previous errors | ||
|