dtolnay / dtolnay/case-studies

Autoref specialization doesn’t seem to work with associated types

Open
#13 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
52
PR merge metrics
No merged PRs in 30d

Description

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:

```rust
trait MyTrait {
type MyAssociatedType;
}

impl MyTrait for &T {
type MyAssociatedType = bool;
}

impl MyTrait for String {
type MyAssociatedType = str;
}

fn get_toy_example(input: T): ::MyAssociatedType {
...
}
```

As far as I can tell the issue is simply that Autoref does not apply to the `` 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.