about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/filter_map_map.rs20
-rw-r--r--clippy_lints/src/methods/mod.rs18
2 files changed, 22 insertions, 16 deletions
diff --git a/clippy_lints/src/methods/filter_map_map.rs b/clippy_lints/src/methods/filter_map_map.rs
new file mode 100644
index 00000000000..d015b4c7b38
--- /dev/null
+++ b/clippy_lints/src/methods/filter_map_map.rs
@@ -0,0 +1,20 @@
+use crate::utils::{match_trait_method, paths, span_lint_and_help};
+use rustc_hir as hir;
+use rustc_lint::LateContext;
+
+use super::FILTER_MAP;
+
+/// lint use of `filter_map().map()` for `Iterators`
+pub(super) fn check<'tcx>(
+    cx: &LateContext<'tcx>,
+    expr: &'tcx hir::Expr<'_>,
+    _filter_args: &'tcx [hir::Expr<'_>],
+    _map_args: &'tcx [hir::Expr<'_>],
+) {
+    // lint if caller of `.filter_map().map()` is an Iterator
+    if match_trait_method(cx, expr, &paths::ITERATOR) {
+        let msg = "called `filter_map(..).map(..)` on an `Iterator`";
+        let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
+        span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
+    }
+}
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 61d562cbc28..2e5dc857b44 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -5,6 +5,7 @@ mod expect_used;
 mod filetype_is_file;
 mod filter_map;
 mod filter_map_identity;
+mod filter_map_map;
 mod filter_next;
 mod from_iter_instead_of_collect;
 mod get_unwrap;
@@ -1700,7 +1701,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
             ["next", "skip_while"] => skip_while_next::check(cx, expr, arg_lists[1]),
             ["next", "iter"] => iter_next_slice::check(cx, expr, arg_lists[1]),
             ["map", "filter"] => filter_map::check(cx, expr, false),
-            ["map", "filter_map"] => lint_filter_map_map(cx, expr, arg_lists[1], arg_lists[0]),
+            ["map", "filter_map"] => filter_map_map::check(cx, expr, arg_lists[1], arg_lists[0]),
             ["next", "filter_map"] => lint_filter_map_next(cx, expr, arg_lists[1], self.msrv.as_ref()),
             ["map", "find"] => filter_map::check(cx, expr, true),
             ["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>(
     }
 }
 
-/// lint use of `filter_map().map()` for `Iterators`
-fn lint_filter_map_map<'tcx>(
-    cx: &LateContext<'tcx>,
-    expr: &'tcx hir::Expr<'_>,
-    _filter_args: &'tcx [hir::Expr<'_>],
-    _map_args: &'tcx [hir::Expr<'_>],
-) {
-    // lint if caller of `.filter_map().map()` is an Iterator
-    if match_trait_method(cx, expr, &paths::ITERATOR) {
-        let msg = "called `filter_map(..).map(..)` on an `Iterator`";
-        let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
-        span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
-    }
-}
-
 /// lint use of `filter().flat_map()` for `Iterators`
 fn lint_filter_flat_map<'tcx>(
     cx: &LateContext<'tcx>,