In one sentence: Rust's orphan rule is not really "either the trait or the type in impl Trait for Type must be yours." Precisely, it is "scanning the Self type and then the trait's type arguments, no bare type parameter may appear before the first local type." If a library leaves a spare type parameter such as Ctx on its trait, users can hang someone else's types off someone else's trait by using their own marker type as the "stem."

Why now

The problem

The classic case: a serializer crate defines ToJson, the uuid crate defines Uuid, and your app wants to glue them together.

impl ToJson for uuid::Uuid {          // both foreign
    fn to_json(&self) -> String { format!("\"{}\"", self) }
}
// error[E0117]: only traits defined in the current crate can be
// implemented for types defined outside of the crate

Why is this forbidden? If crate A could emit hyphenated UUIDs and crate B 32 raw hex digits with the same impl, a program depending on both could not decide which uuid.to_json() should call. Rust guarantees coherence (exactly one implementation per trait/type pair), and the orphan rule is how it enforces it. The Reference also names the goals of preventing builds from breaking just because a dependency was added or updated, and letting library authors add impls without breaking downstream code.

The two common workarounds both hurt.

  1. Build it into the trait crate: the with-uuid, with-chrono, with-jiff, … feature-flag approach. It tries to enumerate an open ecosystem inside one crate, so support always lags, you are locked to the other crate's major versions, and users cannot change the behavior (for example ISO-8601 strings vs. integer milliseconds for timestamps).
  2. Wrap it in a newtype: struct MyUuid(pub Uuid). Fine for a couple of types, but wrapping a whole domain model in MyUuid, MyUrl, MyDateTime, … litters the code with .0 and hand-written method delegation. And you still cannot plug your impl into places where the foreign library itself handles a Uuid.

How it works

The precise rule (RFC 2451 / The Rust Reference)

The Reference defines it like this. Given impl<P1..=Pn> Trait<T1..=Tn> for T0, the impl is valid only if at least one of the following is true:

The key point is that the scan covers not only the Self type T0 but also the trait's type arguments T1..Tn. So

pub struct MyApp;                       // a type from your crate
impl ToJson<MyApp> for uuid::Uuid { … } // OK: trait and Uuid are foreign, but MyApp is local

compiles. No other crate knows MyApp, so nobody else can write a conflicting impl.