rust-lang / rust-lang/rust

`#![feature(generic_const_exprs)]` with `zerocopy` crate causes spurious E0391 cycle error in `cargo doc`

Open
#156,945 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_exprs I-cycle T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

#[derive(zerocopy::FromBytes)] pub struct Foo<O>(zerocopy::U32<O>);

I expected to see this happen: cargo doc completes successfully

Instead, this happened: cargo doc fails with error[E0391]: cycle detected when computing revealed normalized predicates

The problem only seems to occur in library crates that also contain a binary. The binary must link to the library, and must have a different name. Only cargo doc seems to be affected; the code compiles, lints and runs correctly. There is no need to actually use #![feature(generic_const_exprs)] for anything; merely enabling the feature is sufficient.

Rust nightly-2025-05-24 or later and zerocopy 0.8.32 or later are required to trigger the bug.

Meta

rustc +nightly --version --verbose:

rustc 1.98.0-nightly (423e3d252 2026-05-24)
binary: rustc
commit-hash: 423e3d2529999d5e57fa0351783d1292b9219ad4
commit-date: 2026-05-24
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6
Full compiler output

 Documenting foo v0.0.0 (/tmp/test)
error[E0391]: cycle detected when computing revealed normalized predicates of `foo::_::_::<impl zerocopy::HasField<foo::_::_::ẕ0, foo::::_::_::{impl#0}::{constant#0}, ValTree(Leaf(0x00000000000000000000000000000000): i128)> for foo::Foo<O>>::{constant#0}`
 --> src/lib.rs:4:10
  |
4 | #[derive(zerocopy::FromBytes)] pub struct Foo<O>(zerocopy::U32<O>);
  |          ^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires computing normalized predicates of `foo::_::_::<impl zerocopy::HasField<foo::_::_::ẕ0, foo::::_::_::{impl#0}::{constant#0}, ValTree(Leaf(0x00000000000000000000000000000000): i128)> for foo::Foo<O>>::{constant#0}`...
 --> src/lib.rs:4:10
  |
4 | #[derive(zerocopy::FromBytes)] pub struct Foo<O>(zerocopy::U32<O>);
  |          ^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing revealed normalized predicates of `foo::_::_::<impl zerocopy::HasField<foo::_::_::ẕ0, foo::::_::_::{impl#0}::{constant#0}, ValTree(Leaf(0x00000000000000000000000000000000): i128)> for foo::Foo<O>>::{constant#0}`, completing the cycle
note: cycle used when computing normalized predicates of `foo::_::_::<impl zerocopy::HasField<foo::_::_::ẕ0, foo::::_::_::{impl#0}::{constant#0}, ValTree(Leaf(0x00000000000000000000000000000000): i128)> for foo::Foo<O>>`
 --> src/lib.rs:4:10
  |
4 | #[derive(zerocopy::FromBytes)] pub struct Foo<O>(zerocopy::U32<O>);
  |          ^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
  = note: this error originates in the derive macro `zerocopy::FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0391`.
error: could not document `foo`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the minimal example in src/lib.rs using the stated nightly and zerocopy versions, then run cargo doc for the library-plus-binary setup. Start with the E0391 query-cycle notes and the rustc query documentation linked in the report. Done means cargo doc completes successfully without affecting compilation, linting, or execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.