Skip to content

Type of const generic can't be associated type. #149214

@theemathas

Description

@theemathas

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 #149203

Meta

Reproducible on the playground with version 1.93.0-nightly (2025-11-21 27b076af7e3e7a363975)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions