Skip to content

Commit 4b6134b

Browse files
committed
update trait_solver_5
1 parent 7caa8a2 commit 4b6134b

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()`
2-
--> examples/trait_solver_5.rs:6:1
3-
|
4-
5 | impl<T, U: Sub<T>> Overlap<T> for U {}
5-
| ----------------------------------- first implementation here
6-
6 | impl<T> Overlap<T> for () {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
8-
|
9-
= note: downstream crates may implement trait `Sub<_>` for type `()`
10-
11-
For more information about this error, try `rustc --explain E0119`.
12-
error: could not compile `code` (example "trait_solver_5") due to 1 previous error

code/examples/trait_solver_5.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
trait Super {}
2-
trait Sub<T>: Super {}
1+
#![crate_type = "lib"]
32

4-
trait Overlap<T> {}
3+
pub trait Super {}
4+
pub trait Sub<T>: Super {}
5+
6+
pub trait Overlap<T> {}
57
impl<T, U: Sub<T>> Overlap<T> for U {}
68
impl<T> Overlap<T> for () {}
7-
8-
fn main() {}

src/trait_solver/5.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Trait Solver 5 @BoxyUwU @WaffleLapkin
1+
# Trait Solver 5 @BoxyUwU @WaffleLapkin @lcnr
22

33
{{#include ../include/quiz-is-wip.md}}
44

@@ -13,6 +13,8 @@
1313
{{#include ../../code/examples/stderr/trait_solver_5.stderr}}
1414
```
1515

16-
<!-- FIXME: explanation (also: doesn't error on newer versions)-->
16+
In order for these impls to overlap the type `()` must implement `Sub<T>` for some type `T`, the `Sub` trait is public so in theory some downstream crate could implement `(): Sub<Local>`. However, the supertrait `Super` cannot be implement for the type `()` by any downstream crates as `impl Super for () {` would not pass the orphan check in downstream crates
17+
18+
If we were to introduce an `impl Super for () {` to this example then coherence would forbid this code.
1719

1820
</details>

0 commit comments

Comments
 (0)