Skip to content

Commit

Permalink
Extract IteratorFalsePositives into option_helpers.rs
Browse files Browse the repository at this point in the history
This was previously duplicated in #3605
  • Loading branch information
phansch committed Jan 2, 2019
1 parent eaaee23 commit 65a9c34
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 71 deletions.
36 changes: 36 additions & 0 deletions tests/auxiliary/option_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,39 @@
macro_rules! opt_map {
($opt:expr, $map:expr) => {($opt).map($map)};
}

/// 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
}
}
36 changes: 1 addition & 35 deletions tests/ui/iter_skip_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,7 @@
#![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
}
}
include!("../auxiliary/option_helpers.rs");

/// Checks implementation of `ITER_SKIP_NEXT` lint
fn iter_skip_next() {
Expand Down
36 changes: 0 additions & 36 deletions tests/ui/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,42 +178,6 @@ impl HasIter {
}
}

/// 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 `FILTER_NEXT` lint
fn filter_next() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
Expand Down

0 comments on commit 65a9c34

Please sign in to comment.