Skip to content

Commit

Permalink
Fix some lints in types that fail dogfood
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 8, 2021
1 parent bb8208d commit db59c35
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
27 changes: 14 additions & 13 deletions clippy_lints/src/types/box_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ use crate::utils::{is_ty_param_diagnostic_item, span_lint_and_help};
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
}
23 changes: 12 additions & 11 deletions clippy_lints/src/types/option_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ use crate::utils::{is_ty_param_diagnostic_item, span_lint};
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
}
26 changes: 13 additions & 13 deletions clippy_lints/src/types/redundant_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db59c35

Please sign in to comment.