Skip to content

Commit 9d031bc

Browse files
committed
search_is_some: move to nursery
See clippy issue 16086 for context
1 parent 4e72c4d commit 9d031bc

File tree

6 files changed

+18
-37
lines changed

6 files changed

+18
-37
lines changed

src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ declare_clippy_lint! {
889889
/// ```
890890
#[clippy::version = "pre 1.29.0"]
891891
pub SEARCH_IS_SOME,
892-
complexity,
892+
nursery,
893893
"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()`)"
894894
}
895895

src/tools/clippy/tests/ui/crashes/ice-9041.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(clippy::search_is_some)]
12
pub struct Thing;
23
//@no-rustfix
34
pub fn has_thing(things: &[Thing]) -> bool {

src/tools/clippy/tests/ui/crashes/ice-9041.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: called `is_some()` after searching an `Iterator` with `find`
2-
--> tests/ui/crashes/ice-9041.rs:5:19
2+
--> tests/ui/crashes/ice-9041.rs:6:19
33
|
44
LL | things.iter().find(|p| is_thing_ready(p)).is_some()
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|p| is_thing_ready(&p))`

src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,23 @@ mod issue9120 {
311311
}
312312
}
313313

314+
// skip this test due to rust-lang/rust-clippy#16086
315+
/*
314316
#[allow(clippy::match_like_matches_macro)]
315317
fn issue15102() {
316318
let values = [None, Some(3)];
317-
let has_even = values.iter().any(|v| matches!(&v, Some(x) if x % 2 == 0));
318-
//~^ search_is_some
319+
let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
320+
~^ search_is_some
319321
println!("{has_even}");
320322

321323
let has_even = values
322324
.iter()
323-
.any(|v| match &v {
324-
//~^ search_is_some
325+
.find(|v| match v {
326+
~^ search_is_some
325327
Some(x) if x % 2 == 0 => true,
326328
_ => false,
327-
});
329+
})
330+
.is_some();
328331
println!("{has_even}");
329332
}
333+
*/

src/tools/clippy/tests/ui/search_is_some_fixable_some.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,23 @@ mod issue9120 {
322322
}
323323
}
324324

325+
// skip this test due to rust-lang/rust-clippy#16086
326+
/*
325327
#[allow(clippy::match_like_matches_macro)]
326328
fn issue15102() {
327329
let values = [None, Some(3)];
328330
let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
329-
//~^ search_is_some
331+
~^ search_is_some
330332
println!("{has_even}");
331333
332334
let has_even = values
333335
.iter()
334336
.find(|v| match v {
335-
//~^ search_is_some
337+
~^ search_is_some
336338
Some(x) if x % 2 == 0 => true,
337339
_ => false,
338340
})
339341
.is_some();
340342
println!("{has_even}");
341343
}
344+
*/

src/tools/clippy/tests/ui/search_is_some_fixable_some.stderr

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -346,32 +346,5 @@ error: called `is_some()` after searching an `Iterator` with `find`
346346
LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some();
347347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))`
348348

349-
error: called `is_some()` after searching an `Iterator` with `find`
350-
--> tests/ui/search_is_some_fixable_some.rs:328:34
351-
|
352-
LL | let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
353-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| matches!(&v, Some(x) if x % 2 == 0))`
354-
355-
error: called `is_some()` after searching an `Iterator` with `find`
356-
--> tests/ui/search_is_some_fixable_some.rs:334:10
357-
|
358-
LL | .find(|v| match v {
359-
| __________^
360-
LL | |
361-
LL | | Some(x) if x % 2 == 0 => true,
362-
LL | | _ => false,
363-
LL | | })
364-
LL | | .is_some();
365-
| |__________________^
366-
|
367-
help: consider using
368-
|
369-
LL ~ .any(|v| match &v {
370-
LL +
371-
LL + Some(x) if x % 2 == 0 => true,
372-
LL + _ => false,
373-
LL ~ });
374-
|
375-
376-
error: aborting due to 51 previous errors
349+
error: aborting due to 49 previous errors
377350

0 commit comments

Comments
 (0)