Refactor empty_enums
: Check the HIR tree before the feature check.
This commit is contained in:
parent
d1dcd918e7
commit
672b8b512a
@ -64,25 +64,21 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
|
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||||
// Only suggest the `never_type` if the feature is enabled
|
if let ItemKind::Enum(..) = item.kind
|
||||||
if !cx.tcx.features().never_type {
|
// Only suggest the `never_type` if the feature is enabled
|
||||||
return;
|
&& cx.tcx.features().never_type
|
||||||
}
|
&& let Some(adt) = cx.tcx.type_of(item.owner_id).instantiate_identity().ty_adt_def()
|
||||||
|
&& adt.variants().is_empty()
|
||||||
if let ItemKind::Enum(..) = item.kind {
|
{
|
||||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
span_lint_and_help(
|
||||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
cx,
|
||||||
if adt.variants().is_empty() {
|
EMPTY_ENUM,
|
||||||
span_lint_and_help(
|
item.span,
|
||||||
cx,
|
"enum with no variants",
|
||||||
EMPTY_ENUM,
|
None,
|
||||||
item.span,
|
"consider using the uninhabited type `!` (never type) or a wrapper \
|
||||||
"enum with no variants",
|
around it to introduce a type which can't be instantiated",
|
||||||
None,
|
);
|
||||||
"consider using the uninhabited type `!` (never type) or a wrapper \
|
|
||||||
around it to introduce a type which can't be instantiated",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user