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
Update manual_is_variant_and documentation to include equality comparison (#15239)
Update `manual_is_variant_and` documentation to include equality
comparison patterns
This commit updates the documentation for the `manual_is_variant_and`
lint to include all linted cases. Previously, the documentation only
mentioned the `.map(f).unwrap_or_default()` pattern, but the lint also
catches equality comparison patterns like `option.map(f) == Some(true)`
and `result.map(f) == Ok(true)`.
changelog: [`manual_is_variant_and`]: Update documentation to include
equality comparison patterns
fixes#15217
Copy file name to clipboardExpand all lines: clippy_lints/src/methods/mod.rs
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3859,6 +3859,7 @@ declare_clippy_lint! {
3859
3859
declare_clippy_lint!{
3860
3860
/// ### What it does
3861
3861
/// 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.
3862
+
/// Also checks for equality comparisons like `option.map(f) == Some(true)` and `result.map(f) == Ok(true)`.
3862
3863
///
3863
3864
/// ### Why is this bad?
3864
3865
/// Readability. These can be written more concisely as `option.is_some_and(f)` and `result.is_ok_and(f)`.
@@ -3869,18 +3870,28 @@ declare_clippy_lint! {
3869
3870
/// # let result: Result<usize, ()> = Ok(1);
3870
3871
/// option.map(|a| a > 10).unwrap_or_default();
3871
3872
/// result.map(|a| a > 10).unwrap_or_default();
3873
+
///
3874
+
/// option.map(|a| a > 10) == Some(true);
3875
+
/// result.map(|a| a > 10) == Ok(true);
3876
+
/// option.map(|a| a > 10) != Some(true);
3877
+
/// result.map(|a| a > 10) != Ok(true);
3872
3878
/// ```
3873
3879
/// Use instead:
3874
3880
/// ```no_run
3875
3881
/// # let option = Some(1);
3876
3882
/// # let result: Result<usize, ()> = Ok(1);
3877
3883
/// option.is_some_and(|a| a > 10);
3878
3884
/// result.is_ok_and(|a| a > 10);
3885
+
///
3886
+
/// option.is_some_and(|a| a > 10);
3887
+
/// result.is_ok_and(|a| a > 10);
3888
+
/// option.is_none_or(|a| a > 10);
3889
+
/// !result.is_ok_and(|a| a > 10);
3879
3890
/// ```
3880
3891
#[clippy::version = "1.77.0"]
3881
3892
pubMANUAL_IS_VARIANT_AND,
3882
3893
pedantic,
3883
-
"using `.map(f).unwrap_or_default()`, which is more succinctly expressed as `is_some_and(f)` or `is_ok_and(f)`"
3894
+
"using `.map(f).unwrap_or_default()` or `.map(f) == Some/Ok(true)`, which are more succinctly expressed as `is_some_and(f)` or `is_ok_and(f)`"
0 commit comments