]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/methods/filter_map_flat_map.rs
Destructure args in methods module
[rust.git] / clippy_lints / src / methods / filter_map_flat_map.rs
1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::is_trait_method;
3 use rustc_hir as hir;
4 use rustc_lint::LateContext;
5 use rustc_span::sym;
6
7 use super::FILTER_MAP;
8
9 /// lint use of `filter_map().flat_map()` for `Iterators`
10 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
11     // lint if caller of `.filter_map().flat_map()` is an Iterator
12     if is_trait_method(cx, expr, sym::Iterator) {
13         let msg = "called `filter_map(..).flat_map(..)` on an `Iterator`";
14         let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
15                     and filtering by returning `iter::empty()`";
16         span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
17     }
18 }