Skip to content

Commit 4511f4e

Browse files
authored
Merge pull request #3273 from maccoda/master
Adding more detail to filter_map lint documentation.
2 parents 492d685 + d129d04 commit 4511f4e

File tree

1 file changed

+13
-2
lines changed
  • clippy_lints/src/methods

1 file changed

+13
-2
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,19 +706,30 @@ declare_clippy_lint! {
706706

707707

708708
/// **What it does:** Checks for `filter_map` calls which could be replaced by `filter` or `map`.
709+
/// More specifically it checks if the closure provided is only performing one of the
710+
/// filter or map operations and suggests the appropriate option.
709711
///
710-
/// **Why is this bad?** Complexity
712+
/// **Why is this bad?** Complexity. The intent is also clearer if only a single
713+
/// operation is being performed.
711714
///
712715
/// **Known problems:** None
713716
///
714717
/// **Example:**
715718
/// ```rust
716719
/// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None });
717720
/// ```
718-
/// This could be written as:
721+
/// As there is no transformation of the argument this could be written as:
719722
/// ```rust
720723
/// let _ = (0..3).filter(|&x| x > 2);
721724
/// ```
725+
///
726+
/// ```rust
727+
/// let _ = (0..4).filter_map(i32::checked_abs);
728+
/// ```
729+
/// As there is no conditional check on the argument this could be written as:
730+
/// ```rust
731+
/// let _ = (0..4).map(i32::checked_abs);
732+
/// ```
722733
declare_clippy_lint! {
723734
pub UNNECESSARY_FILTER_MAP,
724735
complexity,

0 commit comments

Comments
 (0)