Skip to content

#![feature(never_type)] triggers clippy::empty_enums #3414

Description

@rktaxe

The following code:

#![feature(never_type)]
#![warn(clippy::empty_enums)]

#[derive(zerocopy::FromBytes)] pub struct Foo(());

triggers the clippy::empty_enums lint, which is part of the clippy::pedantic group. With the never type now nearing stabilization (rust-lang/rust#155499), it would be nice to have this sorted out reasonably soon.

Activity

  1. githubrobbi commented on Aug 29, 2026

    @githubrobbi

    Some findings from a downstream project (Rust nightly-2026-08-29, zerocopy 0.8.56) that may help pin this down — it is now broader than the #![feature(never_type)] case in the report:

    Why it started firing everywhere. clippy::empty_enums is guarded on cx.tcx.features().never_type(). rust-lang/rust#155499 stabilized never_type on 2026-08-24, so from nightly-2026-08-25 onward that guard is true in every crate, with or without the feature attribute. Any downstream crate that denies clippy::nursery (the lint's group on current clippy; pedantic on older versions) now fails on every zerocopy derive site:

    error: enum with no variants
      --> src/ntfs/boot_sector.rs:15:30
       |
    15 | #[derive(Debug, Clone, Copy, FromBytes, Immutable, KnownLayout)]
       |                              ^^^^^^^^^
       = note: `-D clippy::empty-enums` implied by `-D clippy::nursery`
       = note: this error originates in the derive macro `FromBytes`
    

    Where the enums come from. derive_has_field_struct_union (zerocopy-derive/src/derive/try_from_bytes.rs) emits one uninhabited #vis enum ẕ<field> {} per struct/union field as a type-level field token. They are wrapped in the const _: () = { … } block built by const_block in util.rs, whose #[allow(...)] list covers non_camel_case_types, non_local_definitions, clippy::missing_inline_in_public_items, … but not clippy::empty_enums. Because derive output carries call-site spans, clippy's external-macro suppression does not apply and the diagnostic lands on the user's #[derive] line — so users cannot fix it short of an #[allow] around every derive site.

    Verified fix. Adding clippy::empty_enums to that generated #[allow(...)] list (next to clippy::missing_inline_in_public_items) takes a 14-site workspace from 14 errors to clean under cargo +nightly-2026-08-29 clippy --workspace --all-targets --all-features -- -D warnings, with the lint still enabled for user code. I put that one-line change up as #3600 in case it is useful; happy to close it if you prefer a different shape (e.g. a clippy-side is_from_proc_macro guard).

  2. impervius commented on Nov 17, 2026

    @impervius

    Now that this feature is stable and rust 1.100 is out, clippy (with nursery) does not pass on codebases that uses zerocopy.

  3. added 2 commits that reference this issue on Nov 17, 2026
  4. added
    zerocopy
    zerocopy-derive
    on Nov 20, 2026
  5. added theissue type on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    zerocopyzerocopy-derive

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions