Skip to content

Commit a288f48

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

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@
55
enum Empty {}
66
//~^ empty_enum
77

8+
enum NotReallyEmpty {
9+
#[cfg(false)]
10+
Hidden,
11+
}
12+
13+
enum OneVisibleVariant {
14+
#[cfg(false)]
15+
Hidden,
16+
Visible,
17+
}
18+
819
fn main() {}

0 commit comments

Comments
 (0)