1 use clippy_utils::diagnostics::span_lint_and_then;
2 use clippy_utils::is_trait_method;
3 use clippy_utils::path_to_local;
4 use clippy_utils::source::snippet;
5 use rustc_errors::Applicability;
7 use rustc_hir::{BindingAnnotation, Node, PatKind};
8 use rustc_lint::LateContext;
11 use super::ITER_SKIP_NEXT;
13 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
14 // lint if caller of skip is an Iterator
15 if is_trait_method(cx, expr, sym::Iterator) {
16 let mut application = Applicability::MachineApplicable;
20 expr.span.trim_start(recv.span).unwrap(),
21 "called `skip(..).next()` on an iterator",
24 if let Some(id) = path_to_local(recv);
25 if let Node::Binding(pat) = cx.tcx.hir().get(id);
26 if let PatKind::Binding(ann, _, _, _) = pat.kind;
27 if ann != BindingAnnotation::Mutable;
29 application = Applicability::Unspecified;
32 &format!("for this change `{}` has to be mutable", snippet(cx, pat.span, "..")),
38 expr.span.trim_start(recv.span).unwrap(),
40 format!(".nth({})", snippet(cx, arg.span, "..")),