forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#3605 - phansch:small_methods_ui_test_improvem…
…ent, r=flip1995 UI test cleanup: Extract iter_skip_next from methods.rs cc rust-lang#2038
- Loading branch information
Showing
4 changed files
with
91 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![warn(clippy::iter_skip_next)] | ||
#![allow(clippy::blacklisted_name)] | ||
|
||
/// Struct to generate false positive for Iterator-based lints | ||
#[derive(Copy, Clone)] | ||
struct IteratorFalsePositives { | ||
foo: u32, | ||
} | ||
|
||
impl IteratorFalsePositives { | ||
fn filter(self) -> IteratorFalsePositives { | ||
self | ||
} | ||
|
||
fn next(self) -> IteratorFalsePositives { | ||
self | ||
} | ||
|
||
fn find(self) -> Option<u32> { | ||
Some(self.foo) | ||
} | ||
|
||
fn position(self) -> Option<u32> { | ||
Some(self.foo) | ||
} | ||
|
||
fn rposition(self) -> Option<u32> { | ||
Some(self.foo) | ||
} | ||
|
||
fn nth(self, n: usize) -> Option<u32> { | ||
Some(self.foo) | ||
} | ||
|
||
fn skip(self, _: usize) -> IteratorFalsePositives { | ||
self | ||
} | ||
} | ||
|
||
/// Checks implementation of `ITER_SKIP_NEXT` lint | ||
fn iter_skip_next() { | ||
let mut some_vec = vec![0, 1, 2, 3]; | ||
let _ = some_vec.iter().skip(42).next(); | ||
let _ = some_vec.iter().cycle().skip(42).next(); | ||
let _ = (1..10).skip(10).next(); | ||
let _ = &some_vec[..].iter().skip(3).next(); | ||
let foo = IteratorFalsePositives { foo: 0 }; | ||
let _ = foo.skip(42).next(); | ||
let _ = foo.filter().skip(42).next(); | ||
} | ||
|
||
fn main() {} |
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,28 @@ | ||
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` | ||
--> $DIR/iter_skip_next.rs:52:13 | ||
| | ||
LL | let _ = some_vec.iter().skip(42).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::iter-skip-next` implied by `-D warnings` | ||
|
||
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` | ||
--> $DIR/iter_skip_next.rs:53:13 | ||
| | ||
LL | let _ = some_vec.iter().cycle().skip(42).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` | ||
--> $DIR/iter_skip_next.rs:54:13 | ||
| | ||
LL | let _ = (1..10).skip(10).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` | ||
--> $DIR/iter_skip_next.rs:55:14 | ||
| | ||
LL | let _ = &some_vec[..].iter().skip(3).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
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