Fix some lints in types that fail dogfood
This commit is contained in:
parent
bb8208da2b
commit
db59c35b7e
@ -7,18 +7,19 @@
|
||||
use super::BOX_VEC;
|
||||
|
||||
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(
|
||||
cx,
|
||||
BOX_VEC,
|
||||
hir_ty.span,
|
||||
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
||||
None,
|
||||
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if Some(def_id) == cx.tcx.lang_items().owned_box()
|
||||
&& is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some()
|
||||
{
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
BOX_VEC,
|
||||
hir_ty.span,
|
||||
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
||||
None,
|
||||
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
|
||||
);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -7,17 +7,18 @@
|
||||
use super::OPTION_OPTION;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
|
||||
if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
|
||||
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
|
||||
span_lint(
|
||||
cx,
|
||||
OPTION_OPTION,
|
||||
hir_ty.span,
|
||||
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
|
||||
if cx.tcx.is_diagnostic_item(sym::option_type, def_id)
|
||||
&& is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some()
|
||||
{
|
||||
span_lint(
|
||||
cx,
|
||||
OPTION_OPTION,
|
||||
hir_ty.span,
|
||||
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
|
||||
enum if you need to distinguish all 3 cases",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -63,20 +63,20 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
|
||||
applicability,
|
||||
);
|
||||
true
|
||||
} else if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
REDUNDANT_ALLOCATION,
|
||||
hir_ty.span,
|
||||
"usage of `Rc<&T>`",
|
||||
"try",
|
||||
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
|
||||
applicability,
|
||||
);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
utils::match_borrows_parameter(cx, qpath).map_or(false, |span| {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
REDUNDANT_ALLOCATION,
|
||||
hir_ty.span,
|
||||
"usage of `Rc<&T>`",
|
||||
"try",
|
||||
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
|
||||
applicability,
|
||||
);
|
||||
true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user