11use clippy_utils:: diagnostics:: span_lint_and_help;
2+ use clippy_utils:: span_contains_cfg;
23use rustc_hir:: { Item , ItemKind } ;
34use rustc_lint:: { LateContext , LateLintPass } ;
45use rustc_session:: declare_lint_pass;
@@ -25,10 +26,6 @@ declare_clippy_lint! {
2526 /// matched to mark code unreachable. If the field is not visible, then the struct
2627 /// acts like any other struct with private fields.
2728 ///
28- /// * If the enum has no variants only because all variants happen to be
29- /// [disabled by conditional compilation][cfg], then it would be appropriate
30- /// to allow the lint, with `#[allow(empty_enum)]`.
31- ///
3229 /// For further information, visit
3330 /// [the never type’s documentation][`!`].
3431 ///
@@ -62,11 +59,11 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
6259
6360impl LateLintPass < ' _ > for EmptyEnum {
6461 fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
65- if let ItemKind :: Enum ( ..) = item. kind
62+ if let ItemKind :: Enum ( .., def) = item. kind
63+ && def. variants . is_empty ( )
6664 // Only suggest the `never_type` if the feature is enabled
6765 && cx. tcx . features ( ) . never_type ( )
68- && let Some ( adt) = cx. tcx . type_of ( item. owner_id ) . instantiate_identity ( ) . ty_adt_def ( )
69- && adt. variants ( ) . is_empty ( )
66+ && !span_contains_cfg ( cx, item. span )
7067 {
7168 span_lint_and_help (
7269 cx,
0 commit comments