Skip to content

Commit 805dcd1

Browse files
committed
move filter_map_map to its own module
1 parent 183daeb commit 805dcd1

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::utils::{match_trait_method, paths, span_lint_and_help};
2+
use rustc_hir as hir;
3+
use rustc_lint::LateContext;
4+
5+
use super::FILTER_MAP;
6+
7+
/// lint use of `filter_map().map()` for `Iterators`
8+
pub(super) fn check<'tcx>(
9+
cx: &LateContext<'tcx>,
10+
expr: &'tcx hir::Expr<'_>,
11+
_filter_args: &'tcx [hir::Expr<'_>],
12+
_map_args: &'tcx [hir::Expr<'_>],
13+
) {
14+
// lint if caller of `.filter_map().map()` is an Iterator
15+
if match_trait_method(cx, expr, &paths::ITERATOR) {
16+
let msg = "called `filter_map(..).map(..)` on an `Iterator`";
17+
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
18+
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
19+
}
20+
}

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod expect_used;
55
mod filetype_is_file;
66
mod filter_map;
77
mod filter_map_identity;
8+
mod filter_map_map;
89
mod filter_next;
910
mod from_iter_instead_of_collect;
1011
mod get_unwrap;
@@ -1700,7 +1701,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17001701
["next", "skip_while"] => skip_while_next::check(cx, expr, arg_lists[1]),
17011702
["next", "iter"] => iter_next_slice::check(cx, expr, arg_lists[1]),
17021703
["map", "filter"] => filter_map::check(cx, expr, false),
1703-
["map", "filter_map"] => lint_filter_map_map(cx, expr, arg_lists[1], arg_lists[0]),
1704+
["map", "filter_map"] => filter_map_map::check(cx, expr, arg_lists[1], arg_lists[0]),
17041705
["next", "filter_map"] => lint_filter_map_next(cx, expr, arg_lists[1], self.msrv.as_ref()),
17051706
["map", "find"] => filter_map::check(cx, expr, true),
17061707
["flat_map", "filter"] => lint_filter_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
@@ -2785,21 +2786,6 @@ fn lint_filter_map_next<'tcx>(
27852786
}
27862787
}
27872788

2788-
/// lint use of `filter_map().map()` for `Iterators`
2789-
fn lint_filter_map_map<'tcx>(
2790-
cx: &LateContext<'tcx>,
2791-
expr: &'tcx hir::Expr<'_>,
2792-
_filter_args: &'tcx [hir::Expr<'_>],
2793-
_map_args: &'tcx [hir::Expr<'_>],
2794-
) {
2795-
// lint if caller of `.filter_map().map()` is an Iterator
2796-
if match_trait_method(cx, expr, &paths::ITERATOR) {
2797-
let msg = "called `filter_map(..).map(..)` on an `Iterator`";
2798-
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
2799-
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
2800-
}
2801-
}
2802-
28032789
/// lint use of `filter().flat_map()` for `Iterators`
28042790
fn lint_filter_flat_map<'tcx>(
28052791
cx: &LateContext<'tcx>,

0 commit comments

Comments
 (0)