]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/methods/inspect_for_each.rs
Auto merge of #81238 - RalfJung:copy-intrinsics, r=m-ou-se
[rust.git] / clippy_lints / src / methods / inspect_for_each.rs
1 use rustc_hir as hir;
2 use rustc_lint::LateContext;
3 use rustc_span::source_map::Span;
4
5 use crate::utils::{match_trait_method, paths, span_lint_and_help};
6
7 use super::INSPECT_FOR_EACH;
8
9 /// lint use of `inspect().for_each()` for `Iterators`
10 pub(super) fn lint<'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 }