search_is_some: move to nursery

See clippy issue 16086 for context
This commit is contained in:
Maja Kądziołka 2025-11-14 23:53:58 +01:00
parent 9e98885a97
commit de65837b5b
No known key found for this signature in database
6 changed files with 18 additions and 37 deletions

View file

@ -889,7 +889,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "pre 1.29.0"]
pub SEARCH_IS_SOME,
complexity,
nursery,
"using an iterator or string search followed by `is_some()` or `is_none()`, which is more succinctly expressed as a call to `any()` or `contains()` (with negation in case of `is_none()`)"
}

View file

@ -1,3 +1,4 @@
#![warn(clippy::search_is_some)]
pub struct Thing;
//@no-rustfix
pub fn has_thing(things: &[Thing]) -> bool {

View file

@ -1,5 +1,5 @@
error: called `is_some()` after searching an `Iterator` with `find`
--> tests/ui/crashes/ice-9041.rs:5:19
--> tests/ui/crashes/ice-9041.rs:6:19
|
LL | things.iter().find(|p| is_thing_ready(p)).is_some()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|p| is_thing_ready(&p))`

View file

@ -311,19 +311,23 @@ mod issue9120 {
}
}
// skip this test due to rust-lang/rust-clippy#16086
/*
#[allow(clippy::match_like_matches_macro)]
fn issue15102() {
let values = [None, Some(3)];
let has_even = values.iter().any(|v| matches!(&v, Some(x) if x % 2 == 0));
//~^ search_is_some
let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
~^ search_is_some
println!("{has_even}");
let has_even = values
.iter()
.any(|v| match &v {
//~^ search_is_some
.find(|v| match v {
~^ search_is_some
Some(x) if x % 2 == 0 => true,
_ => false,
});
})
.is_some();
println!("{has_even}");
}
*/

View file

@ -322,20 +322,23 @@ mod issue9120 {
}
}
// skip this test due to rust-lang/rust-clippy#16086
/*
#[allow(clippy::match_like_matches_macro)]
fn issue15102() {
let values = [None, Some(3)];
let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
//~^ search_is_some
~^ search_is_some
println!("{has_even}");
let has_even = values
.iter()
.find(|v| match v {
//~^ search_is_some
~^ search_is_some
Some(x) if x % 2 == 0 => true,
_ => false,
})
.is_some();
println!("{has_even}");
}
*/

View file

@ -346,32 +346,5 @@ error: called `is_some()` after searching an `Iterator` with `find`
LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))`
error: called `is_some()` after searching an `Iterator` with `find`
--> tests/ui/search_is_some_fixable_some.rs:328:34
|
LL | let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| matches!(&v, Some(x) if x % 2 == 0))`
error: called `is_some()` after searching an `Iterator` with `find`
--> tests/ui/search_is_some_fixable_some.rs:334:10
|
LL | .find(|v| match v {
| __________^
LL | |
LL | | Some(x) if x % 2 == 0 => true,
LL | | _ => false,
LL | | })
LL | | .is_some();
| |__________________^
|
help: consider using
|
LL ~ .any(|v| match &v {
LL +
LL + Some(x) if x % 2 == 0 => true,
LL + _ => false,
LL ~ });
|
error: aborting due to 51 previous errors
error: aborting due to 49 previous errors