1 use crate::methods::derefs_to_slice;
2 use crate::utils::{is_type_diagnostic_item, span_lint_and_sugg};
3 use if_chain::if_chain;
4 use rustc_errors::Applicability;
6 use rustc_lint::LateContext;
9 use super::ITER_CLONED_COLLECT;
11 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) {
13 if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type);
14 if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0]));
15 if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
22 "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
25 ".to_vec()".to_string(),
26 Applicability::MachineApplicable,