[generic_const_exprs + adt_const_params] False positive E0391 cycle when const param type itself has a GCE where clause
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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
- #92961 — False positive cycle detection with
generic_const_exprs(similar symptom, different trigger: associated const self-reference inimpl) - #134978 — Cycle error with GCE
whereclause in function (similar symptom, different trigger: associated const access, noadt_const_params) - #112248 — Type inference fails with
adt_const_params+generic_const_exprs - #90455 — Spurious deref errors combining
adt_const_params+generic_const_exprs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example from src/main.rs with the reported rustc nightly version, then compare the cycle trace involving Y::{constant#1}, THIR construction, and type-checking. Trace why the GCE where clause on the const parameter type X<4> is treated as a cycle, and consider the issue resolved when this example compiles without the false-positive E0391 error.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100