Skip to content

Commit 77b8bfb

Browse files
committed
unnecessary_map_or: add non-comparaison tests
1 parent 430235e commit 77b8bfb

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

tests/ui/unnecessary_map_or.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ fn main() {
5151
let r: Result<i32, S> = Ok(3);
5252
let _ = r.is_ok_and(|x| x == 7);
5353

54+
// lint constructs that are not comparaisons as well
55+
let func = |_x| true;
56+
let r: Result<i32, S> = Ok(3);
57+
let _ = r.is_ok_and(func);
58+
let _ = Some(5).is_some_and(func);
59+
5460
#[derive(PartialEq)]
5561
struct S2;
5662
let r: Result<i32, S2> = Ok(4);

tests/ui/unnecessary_map_or.rs

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ fn main() {
5454
let r: Result<i32, S> = Ok(3);
5555
let _ = r.map_or(false, |x| x == 7);
5656

57+
// lint constructs that are not comparaisons as well
58+
let func = |_x| true;
59+
let r: Result<i32, S> = Ok(3);
60+
let _ = r.map_or(false, func);
61+
let _ = Some(5).map_or(false, func);
62+
5763
#[derive(PartialEq)]
5864
struct S2;
5965
let r: Result<i32, S2> = Ok(4);

tests/ui/unnecessary_map_or.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,20 @@ LL | let _ = r.map_or(false, |x| x == 7);
9292
error: this `map_or` is redundant
9393
--> tests/ui/unnecessary_map_or.rs:60:13
9494
|
95+
LL | let _ = r.map_or(false, func);
96+
| ^^^^^^^^^^^^^^^^^^^^^ help: use is_ok_and instead: `r.is_ok_and(func)`
97+
98+
error: this `map_or` is redundant
99+
--> tests/ui/unnecessary_map_or.rs:61:13
100+
|
101+
LL | let _ = Some(5).map_or(false, func);
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(5).is_some_and(func)`
103+
104+
error: this `map_or` is redundant
105+
--> tests/ui/unnecessary_map_or.rs:66:13
106+
|
95107
LL | let _ = r.map_or(false, |x| x == 8);
96108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(r == Ok(8))`
97109

98-
error: aborting due to 13 previous errors
110+
error: aborting due to 15 previous errors
99111

0 commit comments

Comments
 (0)