rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Scoped `impl Trait for Type`

Open Tamschi opened this issue 3 months ago • 39 comments

This may be a bit long. I thought it would be best to go over the interactions with other language features and tooling as well as potential impacts thoroughly in advance, since while the addition to the language itself can be explained quickly, it does interact with a lot of other Rust features and aspects of the crate ecosystem.

In (very) short this is a version of orphan-rule avoidance (i.e. non-unique trait implementations) that does not suffer from either version of "the hashtable problem", does not obscure imports, can be safely ignored unless needed (but is discoverable), is seamlessly compatible with specialisation and tries to strike a good balance between usability and complexity, so that developers are automatically funneled towards correct and unsurprising but also highly compatible code.

I'm aware that there are often rash proposals in this direction, but I believe I've covered all previously-discussed issues. As the overall RFC is a fairly dense read, I've added cross-references and less-formal comments in form of blockquotes to it.


Thanks

  • to @teliosdev for some very early syntax feedback that helped put me on track,
  • to @cofinite for pointing out how scoped implementations allow syntax traits to be used as extension traits,
  • to @thefakeplace and to SkiFire13 in the draft discussion for suggestions on how to make this RFC more approachable and easier to understand.

Rendered

Tamschi avatar May 12 '24 13:05 Tamschi