Skip to content

Bug: false positive for match must be exhaustive when enum uses feature flags  #9910

@ozwaldorf

Description

@ozwaldorf

Environment

  • IntelliJ Rust plugin version: 0.4.185.5086-223
  • Rust toolchain: on nightly, stable, 1.65.0, pretty much every version I try
  • IDE name and version: Clion #CL-223.7571.171
  • Operating system: Manjaro (rolling latest with kernel 5.15.78)

Problem description

When using an enum that is populated using feature flags, and there is only a single entry, matching for that entry incorrectly reports that there are uncaught cases. Adding a _ => unreachable!() clause as suggested by clion to the match then causes clippy and check to error that it's unreachable code because the enum only has a single type.

Steps to reproduce

Using libp2p::identity::Keypair:

#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum Keypair {
    /// An Ed25519 keypair.
    Ed25519(ed25519::Keypair),
    /// An RSA keypair.
    #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
    Rsa(rsa::Keypair),
    /// A Secp256k1 keypair.
    #[cfg(feature = "secp256k1")]
    Secp256k1(secp256k1::Keypair),
    /// An ECDSA keypair.
    #[cfg(feature = "ecdsa")]
    Ecdsa(ecdsa::Keypair),
}

And the match on Keypair with no features enabled on it:

match self {
  Keypair::Ed25519(keypair) => { println!("{keypair:?}") }
}

Will result in a false positive:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsubsystem::cfgIssues related to conditional compilation (processing of `cfg` attributes)subsystem::code insightGeneral label for issues related to code understanding: highlighting, completion, annotation, etc.subsystem::highlightingIssues related to code highlighting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions