Skip to content

[generic_const_exprs + adt_const_params] False positive E0391 cycle when const param type itself has a GCE where clause #153289

@EienMiku

Description

@EienMiku

Summary

A false positive E0391 cycle error occurs when combining adt_const_params and generic_const_exprs: if a struct used as a const generic parameter type itself carries a GCE where clause, using that const parameter inside another GCE where clause triggers a spurious cycle — even when the called function is a trivially simple generic const fn with no where clause of its own.

Code

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

use std::marker::ConstParamTy;

struct T<const B: bool>;

#[derive(PartialEq, Eq, ConstParamTy)]
struct X<const N: usize>
where
    T<{ N == 4 }>:, {}

struct Y<const N: X<4>>
where
    T<{ foo(&N) }>:, {}

const fn foo<T>(_: &T) -> bool {
    true
}

fn main() {}

Error

error[E0391]: cycle detected when building an abstract representation for `Y::{constant#1}`
  --> src\main.rs:16:7
   |
16 |     T<{ foo(&N) }>:, {}
   |       ^^^^^^^^^^^
   |
note: ...which requires building THIR for `Y::{constant#1}`...
  --> src\main.rs:16:7
   |
16 |     T<{ foo(&N) }>:, {}
   |       ^^^^^^^^^^^
note: ...which requires type-checking `Y::{constant#1}`...
  --> src\main.rs:16:7
   |
16 |     T<{ foo(&N) }>:, {}
   |       ^^^^^^^^^^^
   = note: ...which again requires building an abstract representation for `Y::{constant#1}`, completing the cycle
note: cycle used when checking that `Y` is well-formed
  --> src\main.rs:14:1
   |
14 | struct Y<const N: X<4>>
   | ^^^^^^^^^^^^^^^^^^^^^^^

Notes

There is no actual semantic cycle here. foo is a trivial generic function — it takes &T and returns true, with no where clause and no const generic constraints.

The distinguishing characteristic compared to similar issues is that the source of the "complexity" is entirely in the type of the const parameter (X<4>), not in the called function.

Version

rustc 1.96.0-nightly (80381278a 2026-03-01)

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions