Skip to content

Commit a6b514c

Browse files
committed
Auto merge of rust-lang#7059 - camsteffen:filter-map, r=flip1995
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
2 parents 67fad01 + a45faf6 commit a6b514c

File tree

12 files changed

+23
-161
lines changed

12 files changed

+23
-161
lines changed

clippy_lints/src/deprecated_lints.rs

+9
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,12 @@ declare_deprecated_lint! {
125125
pub FIND_MAP,
126126
"this lint has been replaced by `manual_find_map`, a more specific lint"
127127
}
128+
129+
declare_deprecated_lint! {
130+
/// **What it does:** Nothing. This lint has been deprecated.
131+
///
132+
/// **Deprecation reason:** This lint has been replaced by `manual_filter_map`, a
133+
/// more specific lint.
134+
pub FILTER_MAP,
135+
"this lint has been replaced by `manual_filter_map`, a more specific lint"
136+
}

clippy_lints/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
509509
"clippy::find_map",
510510
"this lint has been replaced by `manual_find_map`, a more specific lint",
511511
);
512+
store.register_removed(
513+
"clippy::filter_map",
514+
"this lint has been replaced by `manual_filter_map`, a more specific lint",
515+
);
512516
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
513517

514518
// begin register lints, do not remove this comment, it’s used in `update_lints`
@@ -760,7 +764,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
760764
methods::EXPECT_FUN_CALL,
761765
methods::EXPECT_USED,
762766
methods::FILETYPE_IS_FILE,
763-
methods::FILTER_MAP,
764767
methods::FILTER_MAP_IDENTITY,
765768
methods::FILTER_MAP_NEXT,
766769
methods::FILTER_NEXT,
@@ -1376,7 +1379,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13761379
LintId::of(matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS),
13771380
LintId::of(matches::MATCH_WILD_ERR_ARM),
13781381
LintId::of(matches::SINGLE_MATCH_ELSE),
1379-
LintId::of(methods::FILTER_MAP),
13801382
LintId::of(methods::FILTER_MAP_NEXT),
13811383
LintId::of(methods::IMPLICIT_CLONE),
13821384
LintId::of(methods::INEFFICIENT_TO_STRING),

clippy_lints/src/methods/filter_flat_map.rs

-18
This file was deleted.

clippy_lints/src/methods/filter_map_flat_map.rs

-18
This file was deleted.

clippy_lints/src/methods/filter_map_map.rs

-17
This file was deleted.

clippy_lints/src/methods/mod.rs

+1-39
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ mod clone_on_ref_ptr;
1111
mod expect_fun_call;
1212
mod expect_used;
1313
mod filetype_is_file;
14-
mod filter_flat_map;
1514
mod filter_map;
16-
mod filter_map_flat_map;
1715
mod filter_map_identity;
18-
mod filter_map_map;
1916
mod filter_map_next;
2017
mod filter_next;
2118
mod flat_map_identity;
@@ -472,35 +469,6 @@ declare_clippy_lint! {
472469
"using combinations of `flatten` and `map` which can usually be written as a single method call"
473470
}
474471

475-
declare_clippy_lint! {
476-
/// **What it does:** Checks for usage of `_.filter(_).map(_)`,
477-
/// `_.filter(_).flat_map(_)`, `_.filter_map(_).flat_map(_)` and similar.
478-
///
479-
/// **Why is this bad?** Readability, this can be written more concisely as
480-
/// `_.filter_map(_)`.
481-
///
482-
/// **Known problems:** Often requires a condition + Option/Iterator creation
483-
/// inside the closure.
484-
///
485-
/// **Example:**
486-
/// ```rust
487-
/// let vec = vec![1];
488-
///
489-
/// // Bad
490-
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
491-
///
492-
/// // Good
493-
/// vec.iter().filter_map(|x| if *x == 0 {
494-
/// Some(*x * 2)
495-
/// } else {
496-
/// None
497-
/// });
498-
/// ```
499-
pub FILTER_MAP,
500-
pedantic,
501-
"using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call"
502-
}
503-
504472
declare_clippy_lint! {
505473
/// **What it does:** Checks for usage of `_.filter(_).map(_)` that can be written more simply
506474
/// as `filter_map(_)`.
@@ -1677,7 +1645,6 @@ impl_lint_pass!(Methods => [
16771645
SEARCH_IS_SOME,
16781646
FILTER_NEXT,
16791647
SKIP_WHILE_NEXT,
1680-
FILTER_MAP,
16811648
FILTER_MAP_IDENTITY,
16821649
MANUAL_FILTER_MAP,
16831650
MANUAL_FIND_MAP,
@@ -1965,11 +1932,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
19651932
unnecessary_filter_map::check(cx, expr, arg);
19661933
filter_map_identity::check(cx, expr, arg, span);
19671934
},
1968-
("flat_map", [flm_arg]) => match method_call!(recv) {
1969-
Some(("filter", [_, _], _)) => filter_flat_map::check(cx, expr),
1970-
Some(("filter_map", [_, _], _)) => filter_map_flat_map::check(cx, expr),
1971-
_ => flat_map_identity::check(cx, expr, flm_arg, span),
1972-
},
1935+
("flat_map", [flm_arg]) => flat_map_identity::check(cx, expr, flm_arg, span),
19731936
("flatten", []) => {
19741937
if let Some(("map", [recv, map_arg], _)) = method_call!(recv) {
19751938
map_flatten::check(cx, expr, recv, map_arg);
@@ -1993,7 +1956,6 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
19931956
("filter", [f_arg]) => {
19941957
filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false)
19951958
},
1996-
("filter_map", [_]) => filter_map_map::check(cx, expr),
19971959
("find", [f_arg]) => filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, true),
19981960
_ => {},
19991961
}

clippy_utils/src/attrs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool {
151151

152152
/// Return true if the attributes contain `#[doc(hidden)]`
153153
pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool {
154-
#[allow(clippy::filter_map)]
155154
attrs
156155
.iter()
157156
.filter(|attr| attr.has_name(sym::doc))

lintcheck/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// When a new lint is introduced, we can search the results for new warnings and check for false
66
// positives.
77

8-
#![allow(clippy::filter_map, clippy::collapsible_else_if)]
8+
#![allow(clippy::collapsible_else_if)]
99

1010
use std::ffi::OsStr;
1111
use std::process::Command;

tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
#[warn(clippy::panic_params)]
1212
#[warn(clippy::unknown_clippy_lints)]
1313
#[warn(clippy::find_map)]
14+
#[warn(clippy::filter_map)]
1415

1516
fn main() {}

tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ error: lint `clippy::find_map` has been removed: this lint has been replaced by
7878
LL | #[warn(clippy::find_map)]
7979
| ^^^^^^^^^^^^^^^^
8080

81+
error: lint `clippy::filter_map` has been removed: this lint has been replaced by `manual_filter_map`, a more specific lint
82+
--> $DIR/deprecated.rs:14:8
83+
|
84+
LL | #[warn(clippy::filter_map)]
85+
| ^^^^^^^^^^^^^^^^^^
86+
8187
error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
8288
--> $DIR/deprecated.rs:1:8
8389
|
8490
LL | #[warn(clippy::unstable_as_slice)]
8591
| ^^^^^^^^^^^^^^^^^^^^^^^^^
8692

87-
error: aborting due to 14 previous errors
93+
error: aborting due to 15 previous errors
8894

tests/ui/filter_methods.rs

-25
This file was deleted.

tests/ui/filter_methods.stderr

-39
This file was deleted.

0 commit comments

Comments
 (0)