Skip to content

Commit 6f2567d

Browse files
authored
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
2 parents 7e2d26f + b4fc33a commit 6f2567d

File tree

1 file changed

+12
-1
lines changed
  • clippy_lints/src/methods

1 file changed

+12
-1
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,7 @@ declare_clippy_lint! {
38593859
declare_clippy_lint! {
38603860
/// ### What it does
38613861
/// 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)`.
38623863
///
38633864
/// ### Why is this bad?
38643865
/// 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! {
38693870
/// # let result: Result<usize, ()> = Ok(1);
38703871
/// option.map(|a| a > 10).unwrap_or_default();
38713872
/// 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);
38723878
/// ```
38733879
/// Use instead:
38743880
/// ```no_run
38753881
/// # let option = Some(1);
38763882
/// # let result: Result<usize, ()> = Ok(1);
38773883
/// option.is_some_and(|a| a > 10);
38783884
/// 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);
38793890
/// ```
38803891
#[clippy::version = "1.77.0"]
38813892
pub MANUAL_IS_VARIANT_AND,
38823893
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)`"
38843895
}
38853896

38863897
declare_clippy_lint! {

0 commit comments

Comments
 (0)