Skip to content

clippy::manual_non_exhaustive triggers on #[non_exhaustive] enum #11583

Closed
@chorman0773

Description

@chorman0773

Summary

In my arch-ops library, I have an enum called X86EncodingPrefix representing different prefixes. To simply some encoding code, I use a hidden variant cast to usize to count the number of supported prefixes. The enum is declared #[non_exhaustive] explicitly to indicate that it can be extended with future prefixes as intel comes out with new extensions (and decides that EVEX is insufficient).

Lint Name

manual_non_exhaustive

Reproducer

I tried this code:

#![deny(clippy::manual_non_exhaustive)]

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[non_exhaustive]
pub enum X86EncodingPrefix {
    NoPrefix,
    Rex,
    Rex2,
    Vex,
    Evex,

    #[doc(hidden)]
    __PrefixCount,
}

impl X86EncodingPrefix{
    pub const PREFIX_COUNT: usize = Self::__PrefixCount as usize;
}

I saw this happen:

error: this seems like a manual implementation of the non-exhaustive pattern
  --> src/lib.rs:5:1
   |
5  | / pub enum X86EncodingPrefix {
6  | |     NoPrefix,
7  | |     Rex,
8  | |     Rex2,
...  |
13 | |     __PrefixCount,
14 | | }
   | |_^
   |
help: remove this variant
  --> src/lib.rs:13:5
   |
13 |     __PrefixCount,
   |     ^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(clippy::manual_non_exhaustive)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `playground` (lib) due to previous error

I expected to see this happen:

No Diagnostic, compiles without issue.

Version

rustc 1.74.0-nightly (7b4d9e155 2023-09-28)
binary: rustc
commit-hash: 7b4d9e155fec06583c763f176fc432dc779f1fc6
commit-date: 2023-09-28
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.2

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions