From 137860d4c066216ccbeda745b7da82d72a0816ba Mon Sep 17 00:00:00 2001 From: TmSalviano Date: Tue, 11 Mar 2025 05:24:20 -0300 Subject: [PATCH 1/2] Add: orphan rule rationale. --- src/items/implementations.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/items/implementations.md b/src/items/implementations.md index dff5c03eb..1d3da5efd 100644 --- a/src/items/implementations.md +++ b/src/items/implementations.md @@ -174,6 +174,15 @@ be instantiable with the same set of types for the input type parameters. --> r[items.impl.trait.orphan-rule] #### Orphan rules +r[items.impl.trait.orphan-rule.rationale] +The orphan rules ensure that other peoples code can't break your code, and vice versa. +If an external crate implements an external trait for an external type, and your crate also +implements the same trait for the same type, the compiler wouldn't know which implementation +to use.\ +The orphan rule prevents this by requiring that either the trait or some type in the +implementation is local to your crate, ensuring only one crate defines the implementation and +thereby maintaining coherence. + r[items.impl.trait.orphan-rule.general] Given `impl Trait for T0`, an `impl` is valid only if at least one of the following is true: From 009ebdde96196b1a701e470d32c53e7b91e19e6f Mon Sep 17 00:00:00 2001 From: Tiago <144632256+TmSalviano@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:21:11 -0300 Subject: [PATCH 2/2] Fix: grammar error . Fix: improved semantics Co-authored-by: Josh Triplett --- src/items/implementations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/implementations.md b/src/items/implementations.md index 1d3da5efd..8720ff1a5 100644 --- a/src/items/implementations.md +++ b/src/items/implementations.md @@ -175,7 +175,7 @@ r[items.impl.trait.orphan-rule] #### Orphan rules r[items.impl.trait.orphan-rule.rationale] -The orphan rules ensure that other peoples code can't break your code, and vice versa. +The orphan rule helps ensure that other people's code can't break your code, and vice versa. If an external crate implements an external trait for an external type, and your crate also implements the same trait for the same type, the compiler wouldn't know which implementation to use.\