| //@aux-build:option_helpers.rs |
| #![warn(clippy::manual_is_variant_and)] |
| |
| #[macro_use] |
| extern crate option_helpers; |
| |
| #[rustfmt::skip] |
| fn option_methods() { |
| let opt = Some(1); |
| |
| // Check for `option.map(_).unwrap_or_default()` use. |
| // Single line case. |
| let _ = opt.is_some_and(|x| x > 1); |
| // Multi-line cases. |
| let _ = opt.is_some_and(|x| { |
| x > 1 |
| }); |
| let _ = opt.is_some_and(|x| x > 1); |
| let _ = opt |
| .is_some_and(|x| x > 1); |
| |
| // won't fix because the return type of the closure is not `bool` |
| let _ = opt.map(|x| x + 1).unwrap_or_default(); |
| |
| let opt2 = Some('a'); |
| let _ = opt2.is_some_and(char::is_alphanumeric); // should lint |
| let _ = opt_map!(opt2, |x| x == 'a').unwrap_or_default(); // should not lint |
| } |
| |
| #[rustfmt::skip] |
| fn result_methods() { |
| let res: Result<i32, ()> = Ok(1); |
| |
| // multi line cases |
| let _ = res.is_ok_and(|x| { |
| x > 1 |
| }); |
| let _ = res.is_ok_and(|x| x > 1); |
| |
| // won't fix because the return type of the closure is not `bool` |
| let _ = res.map(|x| x + 1).unwrap_or_default(); |
| |
| let res2: Result<char, ()> = Ok('a'); |
| let _ = res2.is_ok_and(char::is_alphanumeric); // should lint |
| let _ = opt_map!(res2, |x| x == 'a').unwrap_or_default(); // should not lint |
| } |
| |
| fn main() { |
| option_methods(); |
| result_methods(); |
| } |