Skip to content

Commit c8c23bc

Browse files
committed
fix(empty_enum): don't lint if all variants happen to be cfg-d out
1 parent 70de06f commit c8c23bc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

clippy_lints/src/empty_enum.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::span_contains_cfg;
23
use rustc_hir::{Item, ItemKind};
34
use rustc_lint::{LateContext, LateLintPass};
45
use 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,

tests/ui/empty_enum.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,21 @@
55
enum 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+
825
fn main() {}

0 commit comments

Comments
 (0)