logoalt Hacker News

direwolf20today at 1:22 AM1 replyview on HN

How does it handle an implementation of a trait being in scope in one compilation unit and out of scope in another? That's the wicked problem.


Replies

amlutotoday at 3:23 AM

It’s impossible (?) due to the “coherence” rule. A type A can implement a trait B in two places: the crate where A is defined or the crate where B is defined. So if you can see A and B, you know definitely whether A implements B.

The actual rule is more complex due to generics:

https://github.com/rust-lang/rfcs/blob/master/text/2451-re-r...

and that document doesn’t actually seem to think that this particular property is critical.