Skip to content

Commit

Permalink
Deprecate filter_map
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Apr 9, 2021
1 parent 75efc14 commit c842986
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 159 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,6 @@ Released 2018-09-13
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
Expand Down
8 changes: 8 additions & 0 deletions clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,11 @@ declare_deprecated_lint! {
pub FIND_MAP,
"this lint has been replaced by `manual_find_map`, a more specific lint"
}

declare_clippy_lint! {
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This lint was too broad and linted code that is already concise.
pub FILTER_MAP,
"this lint has been removed since it was too broad"
}
2 changes: 0 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
methods::EXPECT_FUN_CALL,
methods::EXPECT_USED,
methods::FILETYPE_IS_FILE,
methods::FILTER_MAP,
methods::FILTER_MAP_IDENTITY,
methods::FILTER_MAP_NEXT,
methods::FILTER_NEXT,
Expand Down Expand Up @@ -1404,7 +1403,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS),
LintId::of(matches::MATCH_WILD_ERR_ARM),
LintId::of(matches::SINGLE_MATCH_ELSE),
LintId::of(methods::FILTER_MAP),
LintId::of(methods::FILTER_MAP_NEXT),
LintId::of(methods::IMPLICIT_CLONE),
LintId::of(methods::INEFFICIENT_TO_STRING),
Expand Down
18 changes: 0 additions & 18 deletions clippy_lints/src/methods/filter_flat_map.rs

This file was deleted.

18 changes: 0 additions & 18 deletions clippy_lints/src/methods/filter_map_flat_map.rs

This file was deleted.

17 changes: 0 additions & 17 deletions clippy_lints/src/methods/filter_map_map.rs

This file was deleted.

40 changes: 1 addition & 39 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ mod clone_on_ref_ptr;
mod expect_fun_call;
mod expect_used;
mod filetype_is_file;
mod filter_flat_map;
mod filter_map;
mod filter_map_flat_map;
mod filter_map_identity;
mod filter_map_map;
mod filter_map_next;
mod filter_next;
mod flat_map_identity;
Expand Down Expand Up @@ -472,35 +469,6 @@ declare_clippy_lint! {
"using combinations of `flatten` and `map` which can usually be written as a single method call"
}

declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.filter(_).map(_)`,
/// `_.filter(_).flat_map(_)`, `_.filter_map(_).flat_map(_)` and similar.
///
/// **Why is this bad?** Readability, this can be written more concisely as
/// `_.filter_map(_)`.
///
/// **Known problems:** Often requires a condition + Option/Iterator creation
/// inside the closure.
///
/// **Example:**
/// ```rust
/// let vec = vec![1];
///
/// // Bad
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
///
/// // Good
/// vec.iter().filter_map(|x| if *x == 0 {
/// Some(*x * 2)
/// } else {
/// None
/// });
/// ```
pub FILTER_MAP,
pedantic,
"using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call"
}

declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.filter(_).map(_)` that can be written more simply
/// as `filter_map(_)`.
Expand Down Expand Up @@ -1677,7 +1645,6 @@ impl_lint_pass!(Methods => [
SEARCH_IS_SOME,
FILTER_NEXT,
SKIP_WHILE_NEXT,
FILTER_MAP,
FILTER_MAP_IDENTITY,
MANUAL_FILTER_MAP,
MANUAL_FIND_MAP,
Expand Down Expand Up @@ -1965,11 +1932,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
unnecessary_filter_map::check(cx, expr, arg);
filter_map_identity::check(cx, expr, arg, span);
},
("flat_map", [flm_arg]) => match method_call!(recv) {
Some(("filter", [_, _], _)) => filter_flat_map::check(cx, expr),
Some(("filter_map", [_, _], _)) => filter_map_flat_map::check(cx, expr),
_ => flat_map_identity::check(cx, expr, flm_arg, span),
},
("flat_map", [flm_arg]) => flat_map_identity::check(cx, expr, flm_arg, span),
("flatten", []) => {
if let Some(("map", [recv, map_arg], _)) = method_call!(recv) {
map_flatten::check(cx, expr, recv, map_arg);
Expand All @@ -1993,7 +1956,6 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
("filter", [f_arg]) => {
filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false)
},
("filter_map", [_]) => filter_map_map::check(cx, expr),
("find", [f_arg]) => filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, true),
_ => {},
}
Expand Down
25 changes: 0 additions & 25 deletions tests/ui/filter_methods.rs

This file was deleted.

39 changes: 0 additions & 39 deletions tests/ui/filter_methods.stderr

This file was deleted.

0 comments on commit c842986

Please sign in to comment.