Ixrec / rust-orphan-rules

An unofficial, experimental place for documenting and gathering feedback on the design problems around Rust's orphan rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use different orphan rules for different traits

Ixrec opened this issue · comments

commented

The main use case here is binary operator traits. "Little Orphan Impls" discusses this use case a lot but ends up arguing that ordering should matter, and it does matter in today's rules, which is a surprise people usually encounter with the binary operator traits.

https://internals.rust-lang.org/t/coherence-rules-for-generic-binary-operator-traits/4778/10 suggests that we could simply make these traits use different orphan rules where ordering does not matter. https://internals.rust-lang.org/t/orphan-rules/1322/11?u=ixrec suggests manually specifying the ordering for orphan rules separately from the actual ordering of type parameters in the public API.

Since changing which orphan rules apply to a trait would obviously be backwards incompatible (and no, even editions can't change that), we probably can't actually do this for std's operator traits. Are there any use cases with third party traits where this would help?

commented

Looks like Scala is considering letting type classes declare whether or not they should be coherent, which is sort of the logical extreme of this idea.