1 use clippy_utils::diagnostics::span_lint;
2 use clippy_utils::source::snippet;
3 use clippy_utils::{higher, SpanlessEq};
4 use clippy_utils::{is_integer_const, is_trait_method};
5 use if_chain::if_chain;
6 use rustc_hir::{Expr, ExprKind, QPath};
7 use rustc_lint::LateContext;
10 use super::RANGE_ZIP_WITH_LEN;
12 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>, zip_arg: &'tcx Expr<'_>) {
14 if is_trait_method(cx, expr, sym::Iterator);
15 // range expression in `.zip()` call: `0..x.len()`
16 if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::Range::hir(zip_arg);
17 if is_integer_const(cx, start, 0);
19 if let ExprKind::MethodCall(len_path, len_recv, [], _) = end.kind;
20 if len_path.ident.name == sym::len;
21 // `.iter()` and `.len()` called on same `Path`
22 if let ExprKind::Path(QPath::Resolved(_, iter_path)) = recv.kind;
23 if let ExprKind::Path(QPath::Resolved(_, len_path)) = len_recv.kind;
24 if SpanlessEq::new(cx).eq_path_segments(iter_path.segments, len_path.segments);
29 &format!("it is more idiomatic to use `{}.iter().enumerate()`",
30 snippet(cx, recv.span, "_"))