Skip to content

Cycle detected when evaluating trait selection obligation #2116

Closed
@zhoukezi

Description

@zhoukezi

With zerocopy 0.8.11, the following code failed to compile:

use zerocopy::*;

#[derive(KnownLayout)]
#[repr(C)]
pub struct Dummy([u8; Self::CONST]);

impl Dummy {
    const CONST: usize = 42;
}
error[E0391]: cycle detected when evaluating trait selection obligation `_::__ZerocopyKnownLayoutMaybeUninit: core::iter::traits::collect::IntoIterator`
  |
note: ...which requires evaluating type-level constant...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires const-evaluating + checking `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires caching mir of `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}` for CTFE...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires elaborating drops for `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires borrow-checking `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires const checking `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires building MIR for `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires match-checking `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:23
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                       ^^^^^^^^^^^
note: ...which requires type-checking `_::__ZerocopyKnownLayoutMaybeUninit::0::{constant#0}`...
 --> src/lib.rs:5:29
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                             ^^^^^
  = note: ...which again requires evaluating trait selection obligation `_::__ZerocopyKnownLayoutMaybeUninit: core::iter::traits::collect::IntoIterator`, completing the cycle
note: cycle used when type-checking `_::<impl at src/lib.rs:3:10: 3:21>::{constant#0}`
 --> src/lib.rs:5:29
  |
5 | pub struct Dummy([u8; Self::CONST]);
  |                             ^^^^^
  = 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

For more information about this error, try `rustc --explain E0391`.

This compiles on 0.8.10.

> rustc --version
rustc 1.83.0 (90b35a623 2024-11-26)
> cargo --version
cargo 1.83.0 (5ffbef321 2024-10-29)
> cat Cargo.toml
[package]
name = "sandbox"
version = "0.1.0"
edition = "2021"

[dependencies]
#zerocopy = { version = "=0.8.11", features = ["derive"] }
zerocopy = { version = "=0.8.10", features = ["derive"] }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions