Type of const generic can't be associated type.
Open
Nobody has claimed this yet.
A-const-generics
A-resolve
C-bug
S-blocked
T-compiler
T-lang
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
struct Thing;
trait Trait {
type Assoc;
}
impl Trait for Thing {
type Assoc = i32;
}
type Alias1 = i32;
type Alias2 = <Thing as Trait>::Assoc;
fn works<const N: Alias1>() {}
fn fails<const N: Alias2>() {}
I expected works and fails to either both compile or both error. Instead, only works compiles:
error: `<Thing as Trait>::Assoc` is forbidden as the type of a const generic parameter
--> src/lib.rs:14:19
|
14 | fn fails<const N: Alias2>() {}
| ^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
See also https://github.com/rust-lang/rust/issues/149203
Meta
Reproducible on the playground with version 1.93.0-nightly (2025-11-21 27b076af7e3e7a363975)
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
Start with the reproducer in the issue and compare how the compiler handles Alias1 and Alias2 as const generic parameter types. Investigate the const-generic type validation involved, then verify that equivalent aliases are either both accepted or both rejected using the shown example.
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