File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -706,19 +706,30 @@ declare_clippy_lint! {
706
706
707
707
708
708
/// **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.
709
711
///
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.
711
714
///
712
715
/// **Known problems:** None
713
716
///
714
717
/// **Example:**
715
718
/// ```rust
716
719
/// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None });
717
720
/// ```
718
- /// This could be written as:
721
+ /// As there is no transformation of the argument this could be written as:
719
722
/// ```rust
720
723
/// let _ = (0..3).filter(|&x| x > 2);
721
724
/// ```
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
+ /// ```
722
733
declare_clippy_lint ! {
723
734
pub UNNECESSARY_FILTER_MAP ,
724
735
complexity,
You can’t perform that action at this time.
0 commit comments