-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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:
rust-clippy/clippy_lints/src/empty_enum.rs
Lines 28 to 30 in 1ecb18a
| /// * 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 thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have