Skip to content

Type mismatch with type alias and associated types #34738

Closed
@arcnmx

Description

@arcnmx

Type aliases using associated types / as to resolve to a concrete type do not work as expected:

trait Tr {
    type Ty;
    fn f(self) -> Self::Ty;
}

impl Tr for () {
    type Ty = f32;

    fn f(self) -> Self::Ty { 0.5 }
}

type TrTy<T> = <T as Tr>::Ty;

fn main() {
    let _: <() as Tr>::Ty = Tr::f(()); // works
    let _: TrTy<()> = Tr::f(()); // error
}
error: mismatched types [--explain E0308]
  --> <anon>:16:23
16 |>     let _: TrTy<()> = Tr::f(()); // error
   |>                       ^^^^^^^^^ expected associated type, found f32
note: expected type `<() as Tr>::Ty`
note:    found type `f32`

playpen repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions