From 78b3073a747b39dea3ddda0ee254f2c2e62e0381 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 22 Apr 2026 14:47:52 +0200 Subject: [PATCH] sembr src/coherence.md --- src/doc/rustc-dev-guide/src/coherence.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/coherence.md b/src/doc/rustc-dev-guide/src/coherence.md index 73f9213bf405..052b0df65503 100644 --- a/src/doc/rustc-dev-guide/src/coherence.md +++ b/src/doc/rustc-dev-guide/src/coherence.md @@ -8,13 +8,14 @@ Coherence checking is what detects both of trait impls and inherent impls overla Overlapping trait impls always produce an error, while overlapping inherent impls result in an error only if they have methods with the same name. -Checking for overlaps is split in two parts. First there's the [overlap check(s)](#overlap-checks), +Checking for overlaps is split in two parts. +First there's the [overlap check(s)](#overlap-checks), which finds overlaps between traits and inherent implementations that the compiler currently knows about. However, Coherence also results in an error if any other impls **could** exist, -even if they are currently unknown. +even if they are currently unknown. This affects impls which may get added to upstream crates in a backwards compatible way, -and impls from downstream crates. +and impls from downstream crates. This is called the Orphan check. ## Overlap checks @@ -25,7 +26,7 @@ Overlap checks always consider pairs of implementations, comparing them to each Overlap checking for inherent impl blocks is done through `fn check_item` (in coherence/inherent_impls_overlap.rs), where you can very clearly see that (at least for small `n`), the check really performs `n^2` -comparisons between impls. +comparisons between impls. In the case of traits, this check is currently done as part of building the [specialization graph](traits/specialization.md), to handle specializing impls overlapping with their parent, but this may change in the future. @@ -37,7 +38,7 @@ Overlapping is sometimes partially allowed: 1. for marker traits 2. under [specialization](traits/specialization.md) -but normally isn't. +but normally isn't. The overlap check has various modes (see [`OverlapMode`]). Importantly, there's the explicit negative impl check, and the implicit negative impl check. @@ -47,9 +48,9 @@ Both try to prove that an overlap is definitely impossible. ### The explicit negative impl check -This check is done in [`impl_intersection_has_negative_obligation`]. +This check is done in [`impl_intersection_has_negative_obligation`]. -This check tries to find a negative trait implementation. +This check tries to find a negative trait implementation. For example: ```rust