mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Ran tests/ui/update-all-references.sh" and
cargo dev fmt`
This commit is contained in:
parent
431fcbcc00
commit
55dc822062
6 changed files with 175 additions and 73 deletions
|
@ -20,71 +20,3 @@ LL | | ).next();
|
|||
|
|
||||
= note: `-D clippy::filter-next` implied by `-D warnings`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:143:22
|
||||
|
|
||||
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
|
||||
|
|
||||
= note: `-D clippy::search-is-some` implied by `-D warnings`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:144:20
|
||||
|
|
||||
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:145:20
|
||||
|
|
||||
LL | let _ = (0..1).find(|x| *x == 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:146:22
|
||||
|
|
||||
LL | let _ = v.iter().find(|x| **x == 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:149:13
|
||||
|
|
||||
LL | let _ = v.iter().find(|&x| {
|
||||
| _____________^
|
||||
LL | | *x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:155:22
|
||||
|
|
||||
LL | let _ = v.iter().position(|&x| x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:158:13
|
||||
|
|
||||
LL | let _ = v.iter().position(|&x| {
|
||||
| _____________^
|
||||
LL | | x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:164:22
|
||||
|
|
||||
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/methods.rs:167:13
|
||||
|
|
||||
LL | let _ = v.iter().rposition(|&x| {
|
||||
| _____________^
|
||||
LL | | x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[macro_use]
|
||||
// aux-build:option_helpers.rs
|
||||
extern crate option_helpers;
|
||||
use option_helpers::IteratorFalsePositives;
|
||||
|
||||
|
@ -36,4 +36,3 @@ fn main() {
|
|||
// `Pattern` that is not a string
|
||||
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
|
||||
}
|
||||
|
||||
|
|
42
tests/ui/search_is_some.stderr
Normal file
42
tests/ui/search_is_some.stderr
Normal file
|
@ -0,0 +1,42 @@
|
|||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some.rs:13:13
|
||||
|
|
||||
LL | let _ = v.iter().find(|&x| {
|
||||
| _____________^
|
||||
LL | | *x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
|
||||
= note: `-D clippy::search-is-some` implied by `-D warnings`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some.rs:19:13
|
||||
|
|
||||
LL | let _ = v.iter().position(|&x| {
|
||||
| _____________^
|
||||
LL | | x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some.rs:25:13
|
||||
|
|
||||
LL | let _ = v.iter().rposition(|&x| {
|
||||
| _____________^
|
||||
LL | | x < 0
|
||||
LL | | }
|
||||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
error: use of a blacklisted/placeholder name `foo`
|
||||
--> $DIR/search_is_some.rs:31:9
|
||||
|
|
||||
LL | let foo = IteratorFalsePositives { foo: 0 };
|
||||
| ^^^
|
||||
|
|
||||
= note: `-D clippy::blacklisted-name` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
35
tests/ui/search_is_some_fixable.fixed
Normal file
35
tests/ui/search_is_some_fixable.fixed
Normal file
|
@ -0,0 +1,35 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::search_is_some)]
|
||||
|
||||
fn main() {
|
||||
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
||||
let y = &&42;
|
||||
|
||||
// Check `find().is_some()`, single-line case.
|
||||
let _ = v.iter().any(|x| *x < 0);
|
||||
let _ = (0..1).any(|x| **y == x); // one dereference less
|
||||
let _ = (0..1).any(|x| x == 0);
|
||||
let _ = v.iter().any(|x| *x == 0);
|
||||
|
||||
// Check `position().is_some()`, single-line case.
|
||||
let _ = v.iter().any(|&x| x < 0);
|
||||
|
||||
// Check `rposition().is_some()`, single-line case.
|
||||
let _ = v.iter().any(|&x| x < 0);
|
||||
|
||||
let s1 = String::from("hello world");
|
||||
let s2 = String::from("world");
|
||||
// caller of `find()` is a `&`static str`
|
||||
let _ = "hello world".contains("world");
|
||||
let _ = "hello world".contains(&s2);
|
||||
let _ = "hello world".contains(&s2[2..]);
|
||||
// caller of `find()` is a `String`
|
||||
let _ = s1.contains("world");
|
||||
let _ = s1.contains(&s2);
|
||||
let _ = s1.contains(&s2[2..]);
|
||||
// caller of `find()` is slice of `String`
|
||||
let _ = s1[2..].contains("world");
|
||||
let _ = s1[2..].contains(&s2);
|
||||
let _ = s1[2..].contains(&s2[2..]);
|
||||
}
|
94
tests/ui/search_is_some_fixable.stderr
Normal file
94
tests/ui/search_is_some_fixable.stderr
Normal file
|
@ -0,0 +1,94 @@
|
|||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:10:22
|
||||
|
|
||||
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
|
||||
|
|
||||
= note: `-D clippy::search-is-some` implied by `-D warnings`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:11:20
|
||||
|
|
||||
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:12:20
|
||||
|
|
||||
LL | let _ = (0..1).find(|x| *x == 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:13:22
|
||||
|
|
||||
LL | let _ = v.iter().find(|x| **x == 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:16:22
|
||||
|
|
||||
LL | let _ = v.iter().position(|&x| x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
|
||||
|
||||
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
|
||||
--> $DIR/search_is_some_fixable.rs:19:22
|
||||
|
|
||||
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:24:27
|
||||
|
|
||||
LL | let _ = "hello world".find("world").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:25:27
|
||||
|
|
||||
LL | let _ = "hello world".find(&s2).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:26:27
|
||||
|
|
||||
LL | let _ = "hello world".find(&s2[2..]).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:28:16
|
||||
|
|
||||
LL | let _ = s1.find("world").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:29:16
|
||||
|
|
||||
LL | let _ = s1.find(&s2).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:30:16
|
||||
|
|
||||
LL | let _ = s1.find(&s2[2..]).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:32:21
|
||||
|
|
||||
LL | let _ = s1[2..].find("world").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains("world")`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:33:21
|
||||
|
|
||||
LL | let _ = s1[2..].find(&s2).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2)`
|
||||
|
||||
error: called `is_some()` after calling `find()` on a string. This is more succinctly expressed by calling `contains()`.
|
||||
--> $DIR/search_is_some_fixable.rs:34:21
|
||||
|
|
||||
LL | let _ = s1[2..].find(&s2[2..]).is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `contains(&s2[2..])`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
Loading…
Reference in a new issue