Skip to content

empty_enum fires on enums that are only empty because of #[cfg] #15910

@ada4a

Description

@ada4a

Summary

The lint fires on enums which happen to have all their variants cfg-d out.

This is called out in the lint description as a known problem:

/// * If the enum has no variants only because all variants happen to be
/// [disabled by conditional compilation][cfg], then it would be appropriate
/// to allow the lint, with `#[allow(empty_enum)]`.

Lint Name

empty_enum

Reproducer

I tried this code:

#![allow(unused)]
#![warn(clippy::empty_enum)]

enum NotReallyEmpty {
    #[cfg(false)]
    PhantomVariant,
}

I saw this happen:

error: enum with no variants
  --> tests/ui/empty_enum.rs:8:1
   |
LL | / enum EmptyWithCfg {
LL | |     #[cfg(false)]
LL | |     PhantomVariant,
LL | | }
   | |_^
   |
   = help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated

I expected to see this happen:
no warning

Version

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

Additional Labels

@rustbot claim

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions