1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::is_ty_param_diagnostic_item;
3 use rustc_hir::{self as hir, def_id::DefId, QPath};
4 use rustc_lint::LateContext;
5 use rustc_span::symbol::sym;
7 use super::BOX_COLLECTION;
9 pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
11 if Some(def_id) == cx.tcx.lang_items().owned_box();
12 if let Some(item_type) = get_std_collection(cx, qpath);
14 let generic = if item_type == "String" {
24 "you seem to be trying to use `Box<{outer}{generic}>`. Consider using just `{outer}{generic}`",
29 "`{outer}{generic}` is already on the heap, `Box<{outer}{generic}>` makes an extra allocation",
40 fn get_std_collection(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> {
41 if is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some() {
43 } else if is_ty_param_diagnostic_item(cx, qpath, sym::string_type).is_some() {
45 } else if is_ty_param_diagnostic_item(cx, qpath, sym::hashmap_type).is_some() {