Skip to content

Commit db59c35

Browse files
committed
Fix some lints in types that fail dogfood
1 parent bb8208d commit db59c35

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

clippy_lints/src/types/box_vec.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ use crate::utils::{is_ty_param_diagnostic_item, span_lint_and_help};
77
use super::BOX_VEC;
88

99
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
10-
if Some(def_id) == cx.tcx.lang_items().owned_box() {
11-
if is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some() {
12-
span_lint_and_help(
13-
cx,
14-
BOX_VEC,
15-
hir_ty.span,
16-
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
17-
None,
18-
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
19-
);
20-
return true;
21-
}
10+
if Some(def_id) == cx.tcx.lang_items().owned_box()
11+
&& is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some()
12+
{
13+
span_lint_and_help(
14+
cx,
15+
BOX_VEC,
16+
hir_ty.span,
17+
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
18+
None,
19+
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
20+
);
21+
true
22+
} else {
23+
false
2224
}
23-
false
2425
}

clippy_lints/src/types/option_option.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ use crate::utils::{is_ty_param_diagnostic_item, span_lint};
77
use super::OPTION_OPTION;
88

99
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
10-
if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
11-
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
12-
span_lint(
13-
cx,
14-
OPTION_OPTION,
15-
hir_ty.span,
16-
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
10+
if cx.tcx.is_diagnostic_item(sym::option_type, def_id)
11+
&& is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some()
12+
{
13+
span_lint(
14+
cx,
15+
OPTION_OPTION,
16+
hir_ty.span,
17+
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
1718
enum if you need to distinguish all 3 cases",
18-
);
19-
return true;
20-
}
19+
);
20+
true
21+
} else {
22+
false
2123
}
22-
false
2324
}

clippy_lints/src/types/redundant_allocation.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
6363
applicability,
6464
);
6565
true
66-
} else if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
67-
let mut applicability = Applicability::MachineApplicable;
68-
span_lint_and_sugg(
69-
cx,
70-
REDUNDANT_ALLOCATION,
71-
hir_ty.span,
72-
"usage of `Rc<&T>`",
73-
"try",
74-
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
75-
applicability,
76-
);
77-
true
7866
} else {
79-
false
67+
utils::match_borrows_parameter(cx, qpath).map_or(false, |span| {
68+
let mut applicability = Applicability::MachineApplicable;
69+
span_lint_and_sugg(
70+
cx,
71+
REDUNDANT_ALLOCATION,
72+
hir_ty.span,
73+
"usage of `Rc<&T>`",
74+
"try",
75+
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
76+
applicability,
77+
);
78+
true
79+
})
8080
}
8181
} else {
8282
false

0 commit comments

Comments
 (0)