1 use crate::utils::{match_trait_method, paths, span_lint_and_help};
3 use rustc_lint::LateContext;
7 /// lint use of `filter().flat_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<'_>],
14 // lint if caller of `.filter().flat_map()` is an Iterator
15 if match_trait_method(cx, expr, &paths::ITERATOR) {
16 let msg = "called `filter(..).flat_map(..)` on an `Iterator`";
17 let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
18 and filtering by returning `iter::empty()`";
19 span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);