Skip to content

Autoref specialization doesn’t seem to work with associated types #13

@KeatonTech

Description

@KeatonTech

Hey David,

Sorry if GitHub Issues isn’t the right forum for this, seemed better than reviving an old Reddit thread. I have gotten Autoref specialization to work well in toy cases, but my actual use case has an associated type in it and that causes things to fall down. As a simple (nonsensical) example:

trait MyTrait {
  type MyAssociatedType; 
}

impl<T: Clone> MyTrait for &T {
  type MyAssociatedType = bool;
}

impl MyTrait for String {
  type MyAssociatedType = str;
}

fn<T: MyTrait> get_toy_example(input: T): <T as MyTrait>::MyAssociatedType {
  ...
}

As far as I can tell the issue is simply that Autoref does not apply to the <T as MyTrait> section, so it will not find implementations for anything other than String. If I change it to <&T as MyTrait> then it will find implementations for all Clone structs but will not special-case String.

The experimental specialization feature built into Rust also falls down for associated types (and seems to be gathering dust) so I’m sort of stuck here. You seem to be the foremost expert on Rust specialization so I figured I’d ask :) Am I hosed here?

If so, might be worth updating the case study doc with that second caveat added. It does come up pretty high up on the Google results for Rust specialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions