Skip to content

Associated types are not correctly computed (at least not at the right time) #28828

Closed
@paholg

Description

@paholg

If I have an associated type that impls some trait or is some other known type, I can't treat it as so. Example (playpen link):

trait DoNothing {
    type Output;
}

struct Bob;
impl Bob {
    fn print() { println!("I AM BOB!"); }
}

impl DoNothing for Bob {
    type Output = Bob;
}

type BobAlso = <Bob as DoNothing>::Output;

fn main() {
    // works fine:
    Bob::print();
    // compiler error:
    BobAlso::print();
}

The type BobAlso is (or should be) just an alias for Bob, however when I try to call its print() function, the compiler complains that there is no print for <Bob as DoNothing>::Output without figuring out that that it is Bob.

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions