]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/clippy_lints/src/methods/iter_nth.rs
1 use super::utils
::derefs_to_slice
;
2 use crate::methods
::iter_nth_zero
;
3 use clippy_utils
::diagnostics
::span_lint_and_help
;
4 use clippy_utils
::ty
::is_type_diagnostic_item
;
6 use rustc_lint
::LateContext
;
7 use rustc_span
::symbol
::sym
;
11 pub(super) fn check
<'tcx
>(
12 cx
: &LateContext
<'tcx
>,
14 iter_recv
: &'tcx hir
::Expr
<'tcx
>,
15 nth_recv
: &hir
::Expr
<'_
>,
16 nth_arg
: &hir
::Expr
<'_
>,
19 let mut_str
= if is_mut { "_mut" }
else { "" }
;
20 let caller_type
= if derefs_to_slice(cx
, iter_recv
, cx
.typeck_results().expr_ty(iter_recv
)).is_some() {
22 } else if is_type_diagnostic_item(cx
, cx
.typeck_results().expr_ty(iter_recv
), sym
::Vec
) {
24 } else if is_type_diagnostic_item(cx
, cx
.typeck_results().expr_ty(iter_recv
), sym
::VecDeque
) {
27 iter_nth_zero
::check(cx
, expr
, nth_recv
, nth_arg
);
28 return; // caller is not a type that we want to lint
35 &format
!("called `.iter{mut_str}().nth()` on a {caller_type}"),
37 &format
!("calling `.get{mut_str}()` is both faster and more readable"),