From ca75ba23459e969212868479a22b6fb34deb4ad8 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 22 Apr 2026 14:49:12 +0200 Subject: [PATCH] improve coherence.md --- src/doc/rustc-dev-guide/src/coherence.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/coherence.md b/src/doc/rustc-dev-guide/src/coherence.md index 052b0df65503..6e4e38b9f794 100644 --- a/src/doc/rustc-dev-guide/src/coherence.md +++ b/src/doc/rustc-dev-guide/src/coherence.md @@ -38,7 +38,7 @@ Overlapping is sometimes partially allowed: 1. for marker traits 2. under [specialization](traits/specialization.md) -but normally isn't. +It 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. @@ -65,7 +65,7 @@ In this example, we'd get: `MyCustomErrorType: From<&str>` and `MyCustomErrorType: From`, giving `?E = &str`. And thus, these two implementations would overlap. -However, libstd provides `&str: !Error`, and therefore guarantees that there +However, libstd provides `&str: !Error`, and therefore guarantees that there will never be a positive implementation of `&str: Error`, and thus there is no overlap. Note that for this kind of negative impl check, we must have explicit negative implementations provided. @@ -78,13 +78,13 @@ This is not currently stable. This check is done in [`impl_intersection_has_impossible_obligation`], and does not rely on negative trait implementations and is stable. -Let's say there's a +Let's say there's a ```rust impl From for Box {} // in your own crate impl From for Box where E: Error {} // in std ``` -This would give: `Box: From`, and `Box: From`, +This would give: `Box: From`, and `Box: From`, giving `?E = MyLocalType`. In your crate there's no `MyLocalType: Error`, downstream crates cannot implement `Error` (a remote trait) for `MyLocalType` (a remote type). @@ -92,4 +92,3 @@ Therefore, these two impls do not overlap. Importantly, this works even if there isn't a `impl !Error for MyLocalType`. [`impl_intersection_has_impossible_obligation`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_trait_selection/traits/coherence/fn.impl_intersection_has_impossible_obligation.html -