]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/filter_map_map.rs
Auto merge of #82680 - jturner314:div_euclid-docs, r=JohnTitor
[rust.git] / src / tools / clippy / clippy_lints / src / methods / filter_map_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_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 }