Skip to content

Nightly #![feature(generic_const_exprs)]: cycle detected when building an abstract representation for the const argument #106420

Open
@is8ac

Description

@is8ac

Code:

#![feature(generic_const_exprs)]

pub trait Foo<const K: u32> {
    type T;
}

struct Bar<const A: u32>
where
    (): Foo<{A as u32}>,
    //(): Foo<A>,
    <() as Foo<A>>::T: Sized,
{}

fn main() {}

Error:

error[E0391]: cycle detected when building an abstract representation for the const argument `Bar::{constant#0}`
 --> src/bin/clone_demo2.rs:9:13
  |
9 |     (): Foo<{A as u32}>,
  |             ^^^^^^^^^^
  |
note: ...which requires building THIR for `Bar::{constant#0}`...
 --> src/bin/clone_demo2.rs:9:13
  |
9 |     (): Foo<{A as u32}>,
  |             ^^^^^^^^^^
note: ...which requires type-checking the const argument `Bar::{constant#0}`...
 --> src/bin/clone_demo2.rs:9:13
  |
9 |     (): Foo<{A as u32}>,
  |             ^^^^^^^^^^
note: ...which requires computing normalized predicates of `Bar::{constant#0}`...
 --> src/bin/clone_demo2.rs:9:13
  |
9 |     (): Foo<{A as u32}>,
  |             ^^^^^^^^^^
  = note: ...which again requires building an abstract representation for the const argument `Bar::{constant#0}`, completing the cycle
note: cycle used when computing normalized predicates of `Bar`
 --> src/bin/clone_demo2.rs:7:1
  |
7 | struct Bar<const A: u32>
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted

To work around, replace {A as u32} with A.

The same issue happens with <() as Foo<{A as u32}>>::T: Sized,.

May be related to #106419 ?

Meta

rustc --version --verbose:

rustc 1.68.0-nightly (d6f99e535 2023-01-02)
binary: rustc
commit-hash: d6f99e535a301a421dfee52a7c25bb4bdf420344
commit-date: 2023-01-02
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`I-cycleIssue: A query cycle occurred while none was expectedP-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions