Skip to content

Commit 672b8b5

Browse files
committed
Refactor empty_enums: Check the HIR tree before the feature check.
1 parent d1dcd91 commit 672b8b5

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

clippy_lints/src/empty_enum.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,21 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
6464

6565
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
6666
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
67-
// Only suggest the `never_type` if the feature is enabled
68-
if !cx.tcx.features().never_type {
69-
return;
70-
}
71-
72-
if let ItemKind::Enum(..) = item.kind {
73-
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
74-
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
75-
if adt.variants().is_empty() {
76-
span_lint_and_help(
77-
cx,
78-
EMPTY_ENUM,
79-
item.span,
80-
"enum with no variants",
81-
None,
82-
"consider using the uninhabited type `!` (never type) or a wrapper \
83-
around it to introduce a type which can't be instantiated",
84-
);
85-
}
67+
if let ItemKind::Enum(..) = item.kind
68+
// Only suggest the `never_type` if the feature is enabled
69+
&& cx.tcx.features().never_type
70+
&& let Some(adt) = cx.tcx.type_of(item.owner_id).instantiate_identity().ty_adt_def()
71+
&& adt.variants().is_empty()
72+
{
73+
span_lint_and_help(
74+
cx,
75+
EMPTY_ENUM,
76+
item.span,
77+
"enum with no variants",
78+
None,
79+
"consider using the uninhabited type `!` (never type) or a wrapper \
80+
around it to introduce a type which can't be instantiated",
81+
);
8682
}
8783
}
8884
}

0 commit comments

Comments
 (0)