rust-lang / rust-lang/rust

Type of const generic can't be associated type.

Open
#149,214 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.