use super::BOX_VEC;
-pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) {
+pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
if Some(def_id) == cx.tcx.lang_items().owned_box() {
if is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some() {
span_lint_and_help(
None,
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
);
+ return true;
}
}
+ false
}
let hir_id = hir_ty.hir_id;
let res = cx.qpath_res(qpath, hir_id);
if let Some(def_id) = res.opt_def_id() {
- box_vec::check(cx, hir_ty, qpath, def_id);
- redundant_allocation::check(cx, hir_ty, qpath, def_id);
- rc_buffer::check(cx, hir_ty, qpath, def_id);
- vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold);
+ let mut triggered = false;
+ triggered |= box_vec::check(cx, hir_ty, qpath, def_id);
+ triggered |= redundant_allocation::check(cx, hir_ty, qpath, def_id);
+ triggered |= rc_buffer::check(cx, hir_ty, qpath, def_id);
+ triggered |= vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold);
if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
);
return; // don't recurse into the type
}
+
+ if triggered {
+ return;
+ }
}
match *qpath {
QPath::Resolved(Some(ref ty), ref p) => {
use super::RC_BUFFER;
-pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) {
+pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
if cx.tcx.is_diagnostic_item(sym::Rc, def_id) {
if let Some(alternate) = match_buffer_type(cx, qpath) {
span_lint_and_sugg(
} else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::vec_type) {
let qpath = match &ty.kind {
TyKind::Path(qpath) => qpath,
- _ => return,
+ _ => return false,
};
let inner_span = match get_qpath_generic_tys(qpath).next() {
Some(ty) => ty.span,
- None => return,
+ None => return false,
};
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
),
Applicability::MachineApplicable,
);
+ return true;
}
} else if cx.tcx.is_diagnostic_item(sym::Arc, def_id) {
if let Some(alternate) = match_buffer_type(cx, qpath) {
} else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::vec_type) {
let qpath = match &ty.kind {
TyKind::Path(qpath) => qpath,
- _ => return,
+ _ => return false,
};
let inner_span = match get_qpath_generic_tys(qpath).next() {
Some(ty) => ty.span,
- None => return,
+ None => return false,
};
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
),
Applicability::MachineApplicable,
);
+ return true;
}
}
+
+ false
}
fn match_buffer_type(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> {
use super::{utils, REDUNDANT_ALLOCATION};
-pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) {
+pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
if Some(def_id) == cx.tcx.lang_items().owned_box() {
if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
let mut applicability = Applicability::MachineApplicable;
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
applicability,
);
- return;
+ return true;
}
}
snippet_with_applicability(cx, ty.span, "..", &mut applicability).to_string(),
applicability,
);
+ true
} else if let Some(ty) = is_ty_param_lang_item(cx, qpath, LangItem::OwnedBox) {
let qpath = match &ty.kind {
TyKind::Path(qpath) => qpath,
- _ => return,
+ _ => return false,
};
let inner_span = match get_qpath_generic_tys(qpath).next() {
Some(ty) => ty.span,
- None => return,
+ None => return false,
};
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
),
applicability,
);
+ true
} else if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
applicability,
);
- return; // don't recurse into the type
+ true
+ } else {
+ false
}
+ } else {
+ false
}
}
qpath: &QPath<'_>,
def_id: DefId,
box_size_threshold: u64,
-) {
+) -> bool {
if cx.tcx.is_diagnostic_item(sym::vec_type, def_id) {
if_chain! {
// Get the _ part of Vec<_>
format!("Vec<{}>", snippet(cx, boxed_ty.span, "..")),
Applicability::MachineApplicable,
);
+ true
+ } else {
+ false
}
}
+ } else {
+ false
}
}