Skip to content

Commit caeaa60

Browse files
committed
Fix some lints in types that fail dogfood
1 parent a7f287f commit caeaa60

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

clippy_lints/src/types/box_vec.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ use crate::utils::{paths, span_lint_and_help};
66
use super::{utils, BOX_VEC};
77

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

clippy_lints/src/types/option_option.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ use crate::utils::{paths, span_lint};
77
use super::{utils, 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 utils::match_type_parameter(cx, qpath, &paths::OPTION).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+
&& utils::match_type_parameter(cx, qpath, &paths::OPTION).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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
6666
applicability,
6767
);
6868
true
69-
} else if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
70-
let mut applicability = Applicability::MachineApplicable;
71-
span_lint_and_sugg(
72-
cx,
73-
REDUNDANT_ALLOCATION,
74-
hir_ty.span,
75-
"usage of `Rc<&T>`",
76-
"try",
77-
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
78-
applicability,
79-
);
80-
true
8169
} else {
82-
false
70+
utils::match_borrows_parameter(cx, qpath).map_or(false, |span| {
71+
let mut applicability = Applicability::MachineApplicable;
72+
span_lint_and_sugg(
73+
cx,
74+
REDUNDANT_ALLOCATION,
75+
hir_ty.span,
76+
"usage of `Rc<&T>`",
77+
"try",
78+
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
79+
applicability,
80+
);
81+
true
82+
})
8383
}
8484
} else {
8585
false

0 commit comments

Comments
 (0)