Skip to content

"ambiguous associated type" when accessing concrete type (but not on generic type) #104119

Open
@RalfJung

Description

@RalfJung

Consider the following code:

trait Memory {
    type Provenance;
}

struct BasicMemory;

impl Memory for BasicMemory {
    type Provenance = ();
}

fn some_fn() {
    let x: BasicMemory::Provenance; // this fails
}

fn some_generic_fn<T: Memory>() {
    let x: T::Provenance; // this works
}

Using Type::Provenance works when Type is a generic parameter that implements the appropriate trait, but strangely fails when Type is a concrete type that implements the appropriate trait. That seems like a bug? Or at least it is an odd limitation that it'd be nice to lift. :)

Thanks to @memoryleak47 for pointing this out!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-inferenceArea: Type inferenceT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions