]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/types/box_vec.rs
Add flags to detect lints are triggered
[rust.git] / clippy_lints / src / types / box_vec.rs
1 use rustc_hir::{self as hir, def_id::DefId, QPath};
2 use rustc_lint::LateContext;
3 use rustc_span::symbol::sym;
4
5 use crate::utils::{is_ty_param_diagnostic_item, span_lint_and_help};
6
7 use super::BOX_VEC;
8
9 pub(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         if is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some() {
12             span_lint_and_help(
13                 cx,
14                 BOX_VEC,
15                 hir_ty.span,
16                 "you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
17                 None,
18                 "`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
19             );
20             return true;
21         }
22     }
23     false
24 }