]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/clippy_lints/src/types/box_vec.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / types / box_vec.rs
CommitLineData
f20569fa
XL
1use rustc_hir::{self as hir, def_id::DefId, QPath};
2use rustc_lint::LateContext;
3use rustc_span::symbol::sym;
4
5use crate::utils::{is_ty_param_diagnostic_item, span_lint_and_help};
6
7use super::BOX_VEC;
8
9pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
10 if Some(def_id) == cx.tcx.lang_items().owned_box()
11 && is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some()
12 {
13 span_lint_and_help(
14 cx,
15 BOX_VEC,
16 hir_ty.span,
17 "you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
18 None,
19 "`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
20 );
21 true
22 } else {
23 false
24 }
25}