[generic_const_exprs] False positive E0391 cycle when `const fn` `where` clause references trait with const param
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 a struct has a const generic parameter of array type, and its where clause calls a const fn that itself has a where clause referencing a const expression.
Code
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
pub struct Trait<const B: bool>;
pub struct Y<const V: [(); 3]>
where
Trait<{ foo(&V) }>:, {}
const fn foo<const N: usize>(x: &[(); N]) -> bool
where
Trait<{ N == 3 }>:,
{
true
}
fn main() {}
Error
error[E0391]: cycle detected when building an abstract representation for `Y::{constant#1}`
--> src\main.rs:8:11
|
8 | Trait<{ foo(&V) }>:, {}
| ^^^^^^^^^^^
|
note: ...which requires building THIR for `Y::{constant#1}`...
--> src\main.rs:8:11
|
8 | Trait<{ foo(&V) }>:, {}
| ^^^^^^^^^^^
note: ...which requires type-checking `Y::{constant#1}`...
--> src\main.rs:8:11
|
8 | Trait<{ foo(&V) }>:, {}
| ^^^^^^^^^^^
= 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:6:1
|
6 | pub struct Y<const V: [(); 3]>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Notes
There is no actual semantic cycle here — this appears to be a false positive. The interaction between a const generic of array type ([(); N]) and a nested where clause const expression in the called const fn seems to confuse the abstract representation builder.
Version
rustc 1.96.0-nightly (80381278a 2026-03-01)
Related Issues
- #92961 — False positive cycle detection with
generic_const_exprs - #106994 —
generic_const_exprsdoes not work properly with const/type param defaults - #134978 — Cycle error with const expression in function
whereclause
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 false-positive E0391 using the provided src/main.rs example, then trace the reported cycle through abstract representation building, THIR construction, and type-checking for Y::{constant#1}. Compare the behavior with related issues #92961, #106994, and #134978; done means this valid example no longer reports a cycle and the regression is covered by a test.
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
- 45/100