]> git.lizzy.rs Git - rust.git/commitdiff
Adding more detail to filter_map lint documentation.
authorDylan Maccora <maccora17@gmail.com>
Sun, 7 Oct 2018 00:24:09 +0000 (11:24 +1100)
committerDylan Maccora <maccora17@gmail.com>
Sun, 7 Oct 2018 00:24:09 +0000 (11:24 +1100)
clippy_lints/src/methods/mod.rs

index 30c82e3969f56f21a08f67eba4271de654c1fb3f..d49a05f5186a3acb71bd0a50103ba1545d510262 100644 (file)
 
 
 /// **What it does:** Checks for `filter_map` calls which could be replaced by `filter` or `map`.
+/// More specifically it checks if the closure provided is only performing one of the
+/// filter or map operations and suggests the appropriate option.
 ///
-/// **Why is this bad?** Complexity
+/// **Why is this bad?** Complexity. The intent is also clearer if only a single
+/// operation is being performed.
 ///
 /// **Known problems:** None
 ///
 /// ```rust
 /// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None });
 /// ```
-/// This could be written as:
+/// As there is no transformation of the argument this could be written as:
 /// ```rust
 /// let _ = (0..3).filter(|&x| x > 2);
 /// ```
+///
+/// ```rust
+/// let _ = (0..4).filter_map(i32::checked_abs);
+/// ```
+/// As there is no conditional check on the argument this could be written as:
+/// ```rust
+/// let _ = (0..4).map(i32::checked_abs);
+/// ```
 declare_clippy_lint! {
     pub UNNECESSARY_FILTER_MAP,
     complexity,