Skip to content

Commit 137860d

Browse files
committed
Add: orphan rule rationale.
1 parent 4d92113 commit 137860d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/items/implementations.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ be instantiable with the same set of types for the input type parameters. -->
174174
r[items.impl.trait.orphan-rule]
175175
#### Orphan rules
176176

177+
r[items.impl.trait.orphan-rule.rationale]
178+
The orphan rules ensure that other peoples code can't break your code, and vice versa.
179+
If an external crate implements an external trait for an external type, and your crate also
180+
implements the same trait for the same type, the compiler wouldn't know which implementation
181+
to use.\
182+
The orphan rule prevents this by requiring that either the trait or some type in the
183+
implementation is local to your crate, ensuring only one crate defines the implementation and
184+
thereby maintaining coherence.
185+
177186
r[items.impl.trait.orphan-rule.general]
178187
Given `impl<P1..=Pn> Trait<T1..=Tn> for T0`, an `impl` is valid only if at
179188
least one of the following is true:

0 commit comments

Comments
 (0)