Skip to content

Commit

Permalink
fix comments after discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Sep 6, 2024
1 parent 8fc6554 commit 0983204
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/coherence.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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.
Both try to apply negative reasoning to prove that an overlap is definitely impossible.
Both try to prove that an overlap is definitely impossible.

[`OverlapMode`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/traits/specialization_graph/enum.OverlapMode.html

Expand All @@ -54,15 +54,17 @@ This check tries to find a negative trait implementation.
For example:

```rust
struct MyCustomErrorType;

struct MyCustomBox<T: ?Sized>(Box<T>)

// both in your own crate
impl From<&str> for MyCustomBox<dyn Error> {}
impl<E> From<E> for MyCustomBox<dyn Error> where E: Error {}
impl From<&str> for MyCustomErrorType {}
impl<E> From<E> for MyCustomErrorType where E: Error {}
```

In this example, we'd get:
`MyCustomBox<dyn Error>: From<&str>` and `MyCustomBox<dyn Error>: From<?E>`, giving `?E = &str`.
`MyCustomErrorType: From<&str>` and `MyCustomErrorType: From<?E>`, giving `?E = &str`.

And thus, these two implementations would overlap.
However, libstd provides `&str: !Error`, and therefore guarantees that there
Expand All @@ -71,7 +73,7 @@ will never be a positive implementation of `&str: Error`, and thus there is no o
Note that for this kind of negative impl check, we must have explicit negative implementations provided.
This is not currently stable.

[`impl_intersection_has_negative_obligation`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_trait_selection/traits/coherence/fn.impl_intersection_has_impossible_obligation.htmlhttps://doc.rust-lang.org/beta/nightly-rustc/rustc_trait_selection/traits/coherence/fn.impl_intersection_has_negative_obligation.html
[`impl_intersection_has_negative_obligation`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_trait_selection/traits/coherence/fn.impl_intersection_has_negative_obligation.html

### The implicit negative impl check

Expand All @@ -93,5 +95,3 @@ 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



0 comments on commit 0983204

Please sign in to comment.