]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/inspect_for_each.rs
Rollup merge of #104504 - compiler-errors:fru-syntax-note, r=estebank
[rust.git] / src / tools / clippy / clippy_lints / src / methods / inspect_for_each.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::{source_map::Span, sym};
6
7 use super::INSPECT_FOR_EACH;
8
9 /// lint use of `inspect().for_each()` for `Iterators`
10 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, inspect_span: Span) {
11     if is_trait_method(cx, expr, sym::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 }