Skip to content

Commit 33fa6be

Browse files
committed
improve coherence.md
1 parent 7c5e03f commit 33fa6be

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/coherence.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Overlapping is sometimes partially allowed:
3838
1. for marker traits
3939
2. under [specialization](traits/specialization.md)
4040

41-
but normally isn't.
41+
It normally isn't.
4242

4343
The overlap check has various modes (see [`OverlapMode`]).
4444
Importantly, there's the explicit negative impl check, and the implicit negative impl check.
@@ -65,7 +65,7 @@ In this example, we'd get:
6565
`MyCustomErrorType: From<&str>` and `MyCustomErrorType: From<?E>`, giving `?E = &str`.
6666

6767
And thus, these two implementations would overlap.
68-
However, libstd provides `&str: !Error`, and therefore guarantees that there
68+
However, libstd provides `&str: !Error`, and therefore guarantees that there
6969
will never be a positive implementation of `&str: Error`, and thus there is no overlap.
7070

7171
Note that for this kind of negative impl check, we must have explicit negative implementations provided.
@@ -78,18 +78,17 @@ This is not currently stable.
7878
This check is done in [`impl_intersection_has_impossible_obligation`],
7979
and does not rely on negative trait implementations and is stable.
8080

81-
Let's say there's a
81+
Let's say there's a
8282
```rust
8383
impl From<MyLocalType> for Box<dyn Error> {} // in your own crate
8484
impl<E> From<E> for Box<dyn Error> where E: Error {} // in std
8585
```
8686

87-
This would give: `Box<dyn Error>: From<MyLocalType>`, and `Box<dyn Error>: From<?E>`,
87+
This would give: `Box<dyn Error>: From<MyLocalType>`, and `Box<dyn Error>: From<?E>`,
8888
giving `?E = MyLocalType`.
8989

9090
In your crate there's no `MyLocalType: Error`, downstream crates cannot implement `Error` (a remote trait) for `MyLocalType` (a remote type).
9191
Therefore, these two impls do not overlap.
9292
Importantly, this works even if there isn't a `impl !Error for MyLocalType`.
9393

9494
[`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
95-

0 commit comments

Comments
 (0)