mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-25 20:07:21 +00:00
Refactor empty_enums
: Check the HIR tree before the feature check.
This commit is contained in:
parent
d1dcd918e7
commit
672b8b512a
1 changed files with 15 additions and 19 deletions
|
@ -64,15 +64,12 @@ 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<'_>) {
|
||||||
|
if let ItemKind::Enum(..) = item.kind
|
||||||
// Only suggest the `never_type` if the feature is enabled
|
// Only suggest the `never_type` if the feature is enabled
|
||||||
if !cx.tcx.features().never_type {
|
&& cx.tcx.features().never_type
|
||||||
return;
|
&& 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();
|
|
||||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
|
||||||
if adt.variants().is_empty() {
|
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
EMPTY_ENUM,
|
EMPTY_ENUM,
|
||||||
|
@ -84,5 +81,4 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue