Skip to content

Commit 7221999

Browse files
committed
Add tests with closure
1 parent abaaf74 commit 7221999

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/ui/search_is_some.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ fn main() {
3636
// check that we don't lint if `find()` is called with
3737
// `Pattern` that is not a string
3838
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
39+
40+
let some_closure = |x: &u32| *x == 0;
41+
let _ = (0..1).find(some_closure).is_some();
3942
}
4043

4144
#[rustfmt::skip]
@@ -70,4 +73,7 @@ fn is_none() {
7073
// check that we don't lint if `find()` is called with
7174
// `Pattern` that is not a string
7275
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none();
76+
77+
let some_closure = |x: &u32| *x == 0;
78+
let _ = (0..1).find(some_closure).is_none();
7379
}

tests/ui/search_is_some.stderr

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ LL | | ).is_some();
3535
|
3636
= help: this is more succinctly expressed by calling `any()`
3737

38+
error: called `is_some()` after searching an `Iterator` with `find`
39+
--> $DIR/search_is_some.rs:41:20
40+
|
41+
LL | let _ = (0..1).find(some_closure).is_some();
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(some_closure)`
43+
3844
error: called `is_none()` after searching an `Iterator` with `find`
39-
--> $DIR/search_is_some.rs:48:13
45+
--> $DIR/search_is_some.rs:51:13
4046
|
4147
LL | let _ = v.iter().find(|&x| {
4248
| _____________^
@@ -48,7 +54,7 @@ LL | | ).is_none();
4854
= help: this is more succinctly expressed by calling `any()` with negation
4955

5056
error: called `is_none()` after searching an `Iterator` with `position`
51-
--> $DIR/search_is_some.rs:54:13
57+
--> $DIR/search_is_some.rs:57:13
5258
|
5359
LL | let _ = v.iter().position(|&x| {
5460
| _____________^
@@ -60,7 +66,7 @@ LL | | ).is_none();
6066
= help: this is more succinctly expressed by calling `any()` with negation
6167

6268
error: called `is_none()` after searching an `Iterator` with `rposition`
63-
--> $DIR/search_is_some.rs:60:13
69+
--> $DIR/search_is_some.rs:63:13
6470
|
6571
LL | let _ = v.iter().rposition(|&x| {
6672
| _____________^
@@ -71,5 +77,11 @@ LL | | ).is_none();
7177
|
7278
= help: this is more succinctly expressed by calling `any()` with negation
7379

74-
error: aborting due to 6 previous errors
80+
error: called `is_none()` after searching an `Iterator` with `find`
81+
--> $DIR/search_is_some.rs:78:13
82+
|
83+
LL | let _ = (0..1).find(some_closure).is_none();
84+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(some_closure)`
85+
86+
error: aborting due to 8 previous errors
7587

0 commit comments

Comments
 (0)