]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/clippy_lints/src/methods/inspect_for_each.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / tools / clippy / clippy_lints / src / methods / inspect_for_each.rs
CommitLineData
f20569fa
XL
1use rustc_hir as hir;
2use rustc_lint::LateContext;
3use rustc_span::source_map::Span;
4
5use crate::utils::{match_trait_method, paths, span_lint_and_help};
6
7use super::INSPECT_FOR_EACH;
8
9/// lint use of `inspect().for_each()` for `Iterators`
10pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, inspect_span: Span) {
11 if match_trait_method(cx, expr, &paths::ITERATOR) {
12 let msg = "called `inspect(..).for_each(..)` on an `Iterator`";
13 let hint = "move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)`";
14 span_lint_and_help(
15 cx,
16 INSPECT_FOR_EACH,
17 inspect_span.with_hi(expr.span.hi()),
18 msg,
19 None,
20 hint,
21 );
22 }
23}