1 use crate::methods::utils::derefs_to_slice;
2 use clippy_utils::diagnostics::span_lint_and_sugg;
3 use clippy_utils::ty::is_type_diagnostic_item;
4 use if_chain::if_chain;
5 use rustc_errors::Applicability;
7 use rustc_lint::LateContext;
10 use super::ITER_CLONED_COLLECT;
12 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, recv: &'tcx hir::Expr<'_>) {
14 if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type);
15 if let Some(slice) = derefs_to_slice(cx, recv, cx.typeck_results().expr_ty(recv));
16 if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
23 "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
26 ".to_vec()".to_string(),
27 Applicability::MachineApplicable,