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 Feb 25, 2021
1 parent a7f287f commit caeaa60
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
26 changes: 13 additions & 13 deletions clippy_lints/src/types/box_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::utils::{paths, span_lint_and_help};
use super::{utils, 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 utils::match_type_parameter(cx, qpath, &paths::VEC).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() && utils::match_type_parameter(cx, qpath, &paths::VEC).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::{paths, span_lint};
use super::{utils, 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 utils::match_type_parameter(cx, qpath, &paths::OPTION).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)
&& utils::match_type_parameter(cx, qpath, &paths::OPTION).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 @@ -66,20 +66,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 caeaa60

Please sign in to comment.