Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update trait_solver_5 #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions code/examples/stderr/trait_solver_5.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()`
--> examples/trait_solver_5.rs:6:1
|
5 | impl<T, U: Sub<T>> Overlap<T> for U {}
| ----------------------------------- first implementation here
6 | impl<T> Overlap<T> for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
|
= note: downstream crates may implement trait `Sub<_>` for type `()`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `code` (example "trait_solver_5") due to 1 previous error
8 changes: 3 additions & 5 deletions code/examples/trait_solver_5.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
trait Super {}
trait Sub<T>: Super {}
pub trait Super {}
pub trait Sub<T>: Super {}

trait Overlap<T> {}
pub trait Overlap<T> {}
impl<T, U: Sub<T>> Overlap<T> for U {}
impl<T> Overlap<T> for () {}

fn main() {}
6 changes: 4 additions & 2 deletions src/trait_solver/5.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Trait Solver 5 @BoxyUwU @WaffleLapkin
# Trait Solver 5 @BoxyUwU @WaffleLapkin @lcnr

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

Expand All @@ -13,6 +13,8 @@
{{#include ../../code/examples/stderr/trait_solver_5.stderr}}
```

<!-- FIXME: explanation (also: doesn't error on newer versions)-->
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

If we were to introduce an `impl Super for () {` to this example then coherence would forbid this code.

</details>
Loading