mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Adding more detail to filter_map lint documentation.
This commit is contained in:
parent
1e0729d48a
commit
d129d049c6
@ -706,8 +706,11 @@ declare_clippy_lint! {
|
||||
|
||||
|
||||
/// **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
|
||||
///
|
||||
@ -715,10 +718,18 @@ declare_clippy_lint! {
|
||||
/// ```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,
|
||||
|
Loading…
Reference in New Issue
Block a user