Skip to content

Commit

Permalink
Auto merge of rust-lang#7059 - camsteffen:filter-map, r=flip1995
Browse files Browse the repository at this point in the history
Deprecate `filter_map`

Since rust-lang#6591, `filter_map` does not even lint `filter().map()`. The cases that are still linted make no sense IMO. So this just removes/deprecates it.

changelog: Deprecate `filter_map` lint

Closes rust-lang#3424
Fixes rust-lang#7050
  • Loading branch information
bors committed Apr 11, 2021
2 parents 67fad01 + a45faf6 commit a6b514c
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 161 deletions.
9 changes: 9 additions & 0 deletions clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ declare_deprecated_lint! {
pub FIND_MAP,
"this lint has been replaced by `manual_find_map`, a more specific lint"
}

declare_deprecated_lint! {
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This lint has been replaced by `manual_filter_map`, a
/// more specific lint.
pub FILTER_MAP,
"this lint has been replaced by `manual_filter_map`, a more specific lint"
}
6 changes: 4 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
"clippy::find_map",
"this lint has been replaced by `manual_find_map`, a more specific lint",
);
store.register_removed(
"clippy::filter_map",
"this lint has been replaced by `manual_filter_map`, a more specific lint",
);
// end deprecated lints, do not remove this comment, it’s used in `update_lints`

// begin register lints, do not remove this comment, it’s used in `update_lints`
Expand Down Expand Up @@ -760,7 +764,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 @@ -1376,7 +1379,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
1 change: 0 additions & 1 deletion clippy_utils/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool {

/// Return true if the attributes contain `#[doc(hidden)]`
pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool {
#[allow(clippy::filter_map)]
attrs
.iter()
.filter(|attr| attr.has_name(sym::doc))
Expand Down
2 changes: 1 addition & 1 deletion lintcheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// When a new lint is introduced, we can search the results for new warnings and check for false
// positives.

#![allow(clippy::filter_map, clippy::collapsible_else_if)]
#![allow(clippy::collapsible_else_if)]

use std::ffi::OsStr;
use std::process::Command;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
#[warn(clippy::panic_params)]
#[warn(clippy::unknown_clippy_lints)]
#[warn(clippy::find_map)]
#[warn(clippy::filter_map)]

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/deprecated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ error: lint `clippy::find_map` has been removed: this lint has been replaced by
LL | #[warn(clippy::find_map)]
| ^^^^^^^^^^^^^^^^

error: lint `clippy::filter_map` has been removed: this lint has been replaced by `manual_filter_map`, a more specific lint
--> $DIR/deprecated.rs:14:8
|
LL | #[warn(clippy::filter_map)]
| ^^^^^^^^^^^^^^^^^^

error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
--> $DIR/deprecated.rs:1:8
|
LL | #[warn(clippy::unstable_as_slice)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 14 previous errors
error: aborting due to 15 previous errors

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 a6b514c

Please sign in to comment.