You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clippy_lints/src/methods/mod.rs
+35-1
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ mod iter_skip_zero;
50
50
mod iter_with_drain;
51
51
mod iterator_step_by_zero;
52
52
mod join_absolute_paths;
53
+
mod manual_is_variant_and;
53
54
mod manual_next_back;
54
55
mod manual_ok_or;
55
56
mod manual_saturating_arithmetic;
@@ -3776,6 +3777,32 @@ declare_clippy_lint! {
3776
3777
"filtering `Result` for `Ok` then force-unwrapping, which can be one type-safe operation"
3777
3778
}
3778
3779
3780
+
declare_clippy_lint!{
3781
+
/// Checks for usage of `option.map(f).unwrap_or_default()` and `result.map(f).unwrap_or_default()` where f is a function or closure that returns the `bool` type.
3782
+
///
3783
+
/// ### Why is this bad?
3784
+
/// Readability. These can be written more concisely as `option.is_some_and(f)` and `result.is_ok_and(f)`.
3785
+
///
3786
+
/// ### Example
3787
+
/// ```no_run
3788
+
/// # let option = Some(1);
3789
+
/// # let result: Result<usize, ()> = Ok(1);
3790
+
/// option.map(|a| a > 10).unwrap_or_default();
3791
+
/// result.map(|a| a > 10).unwrap_or_default();
3792
+
/// ```
3793
+
/// Use instead:
3794
+
/// ```no_run
3795
+
/// # let option = Some(1);
3796
+
/// # let result: Result<usize, ()> = Ok(1);
3797
+
/// option.is_some_and(|a| a > 10);
3798
+
/// result.is_ok_and(|a| a > 10);
3799
+
/// ```
3800
+
#[clippy::version = "1.76.0"]
3801
+
pubMANUAL_IS_VARIANT_AND,
3802
+
pedantic,
3803
+
"using `.map(f).unwrap_or_default()`, which is more succinctly expressed as `is_some_and(f)` or `is_ok_and(f)`"
0 commit comments