]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/filter_flat_map.rs
Auto merge of #82680 - jturner314:div_euclid-docs, r=JohnTitor
[rust.git] / src / tools / clippy / clippy_lints / src / methods / filter_flat_map.rs
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().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<'_>],
13 ) {
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);
20     }
21 }