-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-cycleIssue: A query cycle occurred while none was expectedIssue: A query cycle occurred while none was expectedP-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
- False positive cycle detection with
generic_const_exprs#92961 — False positive cycle detection withgeneric_const_exprs(similar symptom, different trigger: associated const self-reference inimpl) - ICE when using a generic const expression in a where clause #134978 — Cycle error with GCE
whereclause in function (similar symptom, different trigger: associated const access, noadt_const_params) - Type inference fails with
adt_const_paramsandconst_generic_exprsfor associated types #112248 — Type inference fails withadt_const_params+generic_const_exprs - Combining generic_const_exprs with
adt_const_paramstalks about derefs that don't exist in the code #90455 — Spurious deref errors combiningadt_const_params+generic_const_exprs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-cycleIssue: A query cycle occurred while none was expectedIssue: A query cycle occurred while none was expectedP-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.