Skip to content

zerocopy 0.8.60 doesn't compile under Kani: #[cfg(kani)] code uses #[derive(KnownLayout)] without the derive feature #4988

Closed

Description

@feliperodri

Since zerocopy 0.8.60 (released 2026-10-05 23:02 UTC), any crate that depends on zerocopy without its derive feature fails to compile under Kani. The dependency doesn't have to be direct: rand 0.8 pulls zerocopy in through ppv-lite86.

[dependencies]
zerocopy = "=0.8.60"
#[cfg(kani)]
#[kani::proof]
fn check() { assert!(1 + 1 == 2); }
$ cargo kani
error: cannot find derive macro `KnownLayout` in this scope
    --> zerocopy-0.8.60/src/layout.rs:2280:14
error[E0277]: the trait bound `layout::padding_testutil::Aligned<[u8; 8], [u8]>: KnownLayout` is not satisfied
...

Cause. 0.8.60 added this to src/layout.rs:

#[cfg(any(test, kani))]
mod padding_testutil {
    use crate::KnownLayout;

    #[derive(KnownLayout)]
    ...

Kani compiles every crate with --cfg kani, so this module is built for dependencies too. But the KnownLayout derive macro is only available with zerocopy's derive feature, so the module only compiles in zerocopy's own test setup. 0.8.59 doesn't have the module.

Workarounds, both checked with Kani main (1640445da):

  • Pin zerocopy = "=0.8.59", directly or in Cargo.lock.
  • Enable the feature: zerocopy = { version = "0.8.60", features = ["derive"] }.

Impact on Kani's CI. Three cargo-kani tests depend on rand 0.8 and fail the same way: cbmc-unknown-lang-mode, dependencies, and stubbing-validate-random. That makes the required regression check fail on every PR, and on main's nightly runs. A PR pinning them to 0.8.59 follows.

The real fix belongs in zerocopy, either gating the module on test alone or on the derive feature as well. Reported as google/zerocopy#3792.

Activity

  1. added
    [C] Bug
    on Oct 7, 2026
  2. feliperodri commented on Oct 7, 2026

    @feliperodri
    MemberAuthor

    Reported upstream as google/zerocopy#3792. Kani's CI pin: #4989.

  3. feliperodri commented on Oct 11, 2026

    @feliperodri
    MemberAuthor

    Fixed upstream in zerocopy 0.8.61 (google/zerocopy#3792). Only 0.8.60 is affected: if a project pinned it or has it in Cargo.lock, cargo update -p zerocopy is enough. Verified with Kani: a crate depending on zerocopy = "=0.8.62" compiles and verifies, and Kani's three affected cargo-kani tests pass without a pin, so #4989 is closed.

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

    [C] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions