Skip to content

Commit ed3c902

Browse files
Add regression test for manual_is_variant_and extension
1 parent 7955303 commit ed3c902

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

tests/ui/manual_is_variant_and2.fixed

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![warn(clippy::manual_is_variant_and)]
2+
3+
struct Foo<T>(T);
4+
5+
impl<T> Foo<T> {
6+
fn map<F: FnMut(T) -> bool>(self, mut f: F) -> Option<bool> {
7+
Some(f(self.0))
8+
}
9+
}
10+
11+
fn foo() -> Option<bool> {
12+
Some(true)
13+
}
14+
15+
macro_rules! some_true {
16+
() => {
17+
Some(true)
18+
};
19+
}
20+
macro_rules! some_false {
21+
() => {
22+
Some(false)
23+
};
24+
}
25+
26+
fn main() {
27+
let _ = Some(2).is_some_and(|x| x % 2 == 0);
28+
//~^ manual_is_variant_and
29+
let _ = Some(2).is_none_or(|x| x % 2 == 0);
30+
//~^ manual_is_variant_and
31+
let _ = Some(2).is_some_and(|x| x % 2 == 0);
32+
//~^ manual_is_variant_and
33+
let _ = Some(2).is_none_or(|x| x % 2 == 0);
34+
//~^ manual_is_variant_and
35+
let _ = Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0);
36+
//~^ manual_is_variant_and
37+
let _ = !Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0);
38+
//~^ manual_is_variant_and
39+
let _ = !Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0);
40+
//~^ manual_is_variant_and
41+
42+
// Should not lint.
43+
let _ = Foo::<u32>(0).map(|x| x % 2 == 0) == Some(true);
44+
let _ = Some(2).map(|x| x % 2 == 0) != foo();
45+
}

tests/ui/manual_is_variant_and2.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![warn(clippy::manual_is_variant_and)]
2+
3+
struct Foo<T>(T);
4+
5+
impl<T> Foo<T> {
6+
fn map<F: FnMut(T) -> bool>(self, mut f: F) -> Option<bool> {
7+
Some(f(self.0))
8+
}
9+
}
10+
11+
fn foo() -> Option<bool> {
12+
Some(true)
13+
}
14+
15+
macro_rules! some_true {
16+
() => {
17+
Some(true)
18+
};
19+
}
20+
macro_rules! some_false {
21+
() => {
22+
Some(false)
23+
};
24+
}
25+
26+
fn main() {
27+
let _ = Some(2).map(|x| x % 2 == 0) == Some(true);
28+
//~^ manual_is_variant_and
29+
let _ = Some(2).map(|x| x % 2 == 0) != Some(true);
30+
//~^ manual_is_variant_and
31+
let _ = Some(2).map(|x| x % 2 == 0) == some_true!();
32+
//~^ manual_is_variant_and
33+
let _ = Some(2).map(|x| x % 2 == 0) != some_false!();
34+
//~^ manual_is_variant_and
35+
let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) == Ok(true);
36+
//~^ manual_is_variant_and
37+
let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) != Ok(true);
38+
//~^ manual_is_variant_and
39+
let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) != Ok(true);
40+
//~^ manual_is_variant_and
41+
42+
// Should not lint.
43+
let _ = Foo::<u32>(0).map(|x| x % 2 == 0) == Some(true);
44+
let _ = Some(2).map(|x| x % 2 == 0) != foo();
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: called `.map() == Some()`
2+
--> tests/ui/manual_is_variant_and2.rs:27:13
3+
|
4+
LL | let _ = Some(2).map(|x| x % 2 == 0) == Some(true);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_some_and(|x| x % 2 == 0)`
6+
|
7+
= note: `-D clippy::manual-is-variant-and` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::manual_is_variant_and)]`
9+
10+
error: called `.map() != Some()`
11+
--> tests/ui/manual_is_variant_and2.rs:29:13
12+
|
13+
LL | let _ = Some(2).map(|x| x % 2 == 0) != Some(true);
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_none_or(|x| x % 2 == 0)`
15+
16+
error: called `.map() == Some()`
17+
--> tests/ui/manual_is_variant_and2.rs:31:13
18+
|
19+
LL | let _ = Some(2).map(|x| x % 2 == 0) == some_true!();
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_some_and(|x| x % 2 == 0)`
21+
22+
error: called `.map() != Some()`
23+
--> tests/ui/manual_is_variant_and2.rs:33:13
24+
|
25+
LL | let _ = Some(2).map(|x| x % 2 == 0) != some_false!();
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Some(2).is_none_or(|x| x % 2 == 0)`
27+
28+
error: called `.map() == Ok()`
29+
--> tests/ui/manual_is_variant_and2.rs:35:13
30+
|
31+
LL | let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) == Ok(true);
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0)`
33+
34+
error: called `.map() != Ok()`
35+
--> tests/ui/manual_is_variant_and2.rs:37:13
36+
|
37+
LL | let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) != Ok(true);
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `!Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0)`
39+
40+
error: called `.map() != Ok()`
41+
--> tests/ui/manual_is_variant_and2.rs:39:13
42+
|
43+
LL | let _ = Ok::<usize, ()>(2).map(|x| x % 2 == 0) != Ok(true);
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `!Ok::<usize, ()>(2).is_ok_and(|x| x % 2 == 0)`
45+
46+
error: aborting due to 7 previous errors
47+

0 commit comments

Comments
 (0)