2021-03-15 19:55:45 -05:00
|
|
|
use clippy_utils::diagnostics::span_lint_and_help;
|
2021-03-16 11:06:34 -05:00
|
|
|
use clippy_utils::is_trait_method;
|
2021-01-11 16:56:12 -06:00
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_lint::LateContext;
|
2021-03-12 11:09:19 -06:00
|
|
|
use rustc_span::{source_map::Span, sym};
|
2021-01-11 16:56:12 -06:00
|
|
|
|
|
|
|
use super::INSPECT_FOR_EACH;
|
|
|
|
|
|
|
|
/// lint use of `inspect().for_each()` for `Iterators`
|
2021-03-02 10:16:16 -06:00
|
|
|
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, inspect_span: Span) {
|
2021-03-12 11:09:19 -06:00
|
|
|
if is_trait_method(cx, expr, sym::Iterator) {
|
2021-01-11 16:56:12 -06:00
|
|
|
let msg = "called `inspect(..).for_each(..)` on an `Iterator`";
|
|
|
|
let hint = "move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)`";
|
|
|
|
span_lint_and_help(
|
|
|
|
cx,
|
|
|
|
INSPECT_FOR_EACH,
|
|
|
|
inspect_span.with_hi(expr.span.hi()),
|
|
|
|
msg,
|
|
|
|
None,
|
|
|
|
hint,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|