mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
64 lines
1.7 KiB
Rust
64 lines
1.7 KiB
Rust
//@aux-build:proc_macros.rs
|
|
#![warn(clippy::unnecessary_map_or)]
|
|
#![allow(clippy::no_effect)]
|
|
#![allow(clippy::eq_op)]
|
|
#![allow(clippy::unnecessary_lazy_evaluations)]
|
|
#[clippy::msrv = "1.70.0"]
|
|
#[macro_use]
|
|
extern crate proc_macros;
|
|
|
|
fn main() {
|
|
// should trigger
|
|
let _ = (Some(5) == Some(5));
|
|
let _ = (Some(5) != Some(5));
|
|
let _ = (Some(5) == Some(5));
|
|
let _ = Some(5).is_some_and(|n| {
|
|
let _ = n;
|
|
6 >= 5
|
|
});
|
|
let _ = Some(vec![5]).is_some_and(|n| n == [5]);
|
|
let _ = Some(vec![1]).is_some_and(|n| vec![2] == n);
|
|
let _ = Some(5).is_some_and(|n| n == n);
|
|
let _ = Some(5).is_some_and(|n| n == if 2 > 1 { n } else { 0 });
|
|
let _ = Ok::<Vec<i32>, i32>(vec![5]).is_ok_and(|n| n == [5]);
|
|
let _ = (Ok::<i32, i32>(5) == Ok(5));
|
|
let _ = (Some(5) == Some(5)).then(|| 1);
|
|
|
|
// shouldnt trigger
|
|
let _ = Some(5).map_or(true, |n| n == 5);
|
|
let _ = Some(5).map_or(true, |n| 5 == n);
|
|
macro_rules! x {
|
|
() => {
|
|
Some(1)
|
|
};
|
|
}
|
|
// methods lints dont fire on macros
|
|
let _ = x!().map_or(false, |n| n == 1);
|
|
let _ = x!().map_or(false, |n| n == vec![1][0]);
|
|
|
|
msrv_1_69();
|
|
|
|
external! {
|
|
let _ = Some(5).map_or(false, |n| n == 5);
|
|
}
|
|
|
|
with_span! {
|
|
let _ = Some(5).map_or(false, |n| n == 5);
|
|
}
|
|
|
|
// check for presence of PartialEq, and alter suggestion to use `is_ok_and` if absent
|
|
struct S;
|
|
let r: Result<i32, S> = Ok(3);
|
|
let _ = r.is_ok_and(|x| x == 7);
|
|
|
|
#[derive(PartialEq)]
|
|
struct S2;
|
|
let r: Result<i32, S2> = Ok(4);
|
|
let _ = (r == Ok(8));
|
|
}
|
|
|
|
#[clippy::msrv = "1.69.0"]
|
|
fn msrv_1_69() {
|
|
// is_some_and added in 1.70.0
|
|
let _ = Some(5).map_or(false, |n| n == if 2 > 1 { n } else { 0 });
|
|
}
|