mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-21 20:23:12 +00:00
unnecessary_map_or
: add non-comparaison tests
This commit is contained in:
parent
627363e811
commit
d1688b53f1
3 changed files with 25 additions and 1 deletions
|
@ -51,6 +51,12 @@ fn main() {
|
|||
let r: Result<i32, S> = Ok(3);
|
||||
let _ = r.is_ok_and(|x| x == 7);
|
||||
|
||||
// lint constructs that are not comparaisons as well
|
||||
let func = |_x| true;
|
||||
let r: Result<i32, S> = Ok(3);
|
||||
let _ = r.is_ok_and(func);
|
||||
let _ = Some(5).is_some_and(func);
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct S2;
|
||||
let r: Result<i32, S2> = Ok(4);
|
||||
|
|
|
@ -54,6 +54,12 @@ fn main() {
|
|||
let r: Result<i32, S> = Ok(3);
|
||||
let _ = r.map_or(false, |x| x == 7);
|
||||
|
||||
// lint constructs that are not comparaisons as well
|
||||
let func = |_x| true;
|
||||
let r: Result<i32, S> = Ok(3);
|
||||
let _ = r.map_or(false, func);
|
||||
let _ = Some(5).map_or(false, func);
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct S2;
|
||||
let r: Result<i32, S2> = Ok(4);
|
||||
|
|
|
@ -92,8 +92,20 @@ LL | let _ = r.map_or(false, |x| x == 7);
|
|||
error: this `map_or` is redundant
|
||||
--> tests/ui/unnecessary_map_or.rs:60:13
|
||||
|
|
||||
LL | let _ = r.map_or(false, func);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use is_ok_and instead: `r.is_ok_and(func)`
|
||||
|
||||
error: this `map_or` is redundant
|
||||
--> tests/ui/unnecessary_map_or.rs:61:13
|
||||
|
|
||||
LL | let _ = Some(5).map_or(false, func);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(5).is_some_and(func)`
|
||||
|
||||
error: this `map_or` is redundant
|
||||
--> tests/ui/unnecessary_map_or.rs:66:13
|
||||
|
|
||||
LL | let _ = r.map_or(false, |x| x == 8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(r == Ok(8))`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue