about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2018-12-30 12:41:37 +0100
committerPhilipp Hansch <dev@phansch.net>2018-12-30 13:46:21 +0100
commit8c4c458ee93e53cc304d1a839d78ae18c4525b5d (patch)
treebefb9e247e35fcc1269e6ca90370d94843466b49
parent61bfb39e3feaeff417c77155849697a4da039252 (diff)
downloadrust-8c4c458ee93e53cc304d1a839d78ae18c4525b5d.tar.gz
rust-8c4c458ee93e53cc304d1a839d78ae18c4525b5d.zip
UI test cleanup: Extract iter_skip_next from methods.rs
cc #2038
-rw-r--r--tests/ui/iter_skip_next.rs61
-rw-r--r--tests/ui/iter_skip_next.stderr28
-rw-r--r--tests/ui/methods.rs12
-rw-r--r--tests/ui/methods.stderr30
4 files changed, 91 insertions, 40 deletions
diff --git a/tests/ui/iter_skip_next.rs b/tests/ui/iter_skip_next.rs
new file mode 100644
index 00000000000..4628bfbf301
--- /dev/null
+++ b/tests/ui/iter_skip_next.rs
@@ -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() {}
diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr
new file mode 100644
index 00000000000..6b65c1e4a1e
--- /dev/null
+++ b/tests/ui/iter_skip_next.stderr
@@ -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
+
diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs
index ebf71f67a00..b470a12f7a3 100644
--- a/tests/ui/methods.rs
+++ b/tests/ui/methods.rs
@@ -390,18 +390,6 @@ fn iter_nth() {
     let ok_mut = false_positive.iter_mut().nth(3);
 }
 
-/// 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();
-}
-
 #[allow(clippy::similar_names)]
 fn main() {
     let opt = Some(0);
diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr
index b0b693f3e16..e87e61fbe0e 100644
--- a/tests/ui/methods.stderr
+++ b/tests/ui/methods.stderr
@@ -367,39 +367,13 @@ error: called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both fa
 LL |         let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
-  --> $DIR/methods.rs:396: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/methods.rs:397: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/methods.rs:398: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/methods.rs:399:14
-   |
-LL |     let _ = &some_vec[..].iter().skip(3).next();
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
 error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
-  --> $DIR/methods.rs:408:13
+  --> $DIR/methods.rs:396:13
    |
 LL |     let _ = opt.unwrap();
    |             ^^^^^^^^^^^^
    |
    = note: `-D clippy::option-unwrap-used` implied by `-D warnings`
 
-error: aborting due to 50 previous errors
+error: aborting due to 46 previous errors