Currently the coherence rules prevent an external trait from being implemented by an external type. In crates intending to be used by other crates, this makes sense and prevents some very possible problems further down the line. The two problems I see these rules solving are:
- Trait implementations getting lost in a crate’s modules while a user of the crate might not even know of it’s existence.
- If two crates implement the same trait for the same type when neither directly ‘owns’ either, the compiler would have no way of figuring out which to use.
However, there are two situations where these are not problems:
- If the crate is a binary rather than a library, no other crate further down the line can include it and another crate with the same implementation.
- If the implementation could be marked as private to the crate and not used by crates using it as a dependency.
So I’m proposing a new
#[suppress_coherence] that can be used to mark
impl blocks as valid code in binaries, and possibly as crate-private implementations for libraries.