File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 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 ///
@@ -66,6 +63,7 @@ impl LateLintPass<'_> for EmptyEnum {
6663 && def. variants . is_empty ( )
6764 // Only suggest the `never_type` if the feature is enabled
6865 && cx. tcx . features ( ) . never_type ( )
66+ && !span_contains_cfg ( cx, item. span )
6967 {
7068 span_lint_and_help (
7169 cx,
Original file line number Diff line number Diff line change 55enum Empty { }
66//~^ empty_enum
77
8+ mod issue15910 {
9+ enum NotReallyEmpty {
10+ #[ cfg( false ) ]
11+ Hidden ,
12+ }
13+
14+ enum OneVisibleVariant {
15+ #[ cfg( false ) ]
16+ Hidden ,
17+ Visible ,
18+ }
19+
20+ enum CfgInsideVariant {
21+ Variant ( #[ cfg( false ) ] String ) ,
22+ }
23+ }
24+
825fn main ( ) { }
You can’t perform that action at this time.
0 commit comments