From b31b6cb6c2ed683778f32b4708d8e6abe5e84f5d Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 19 Dec 2024 04:28:59 +0000 Subject: [PATCH] update trait_solver_5 --- code/examples/stderr/trait_solver_5.stderr | 12 ------------ code/examples/trait_solver_5.rs | 8 +++----- src/trait_solver/5.md | 6 ++++-- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/code/examples/stderr/trait_solver_5.stderr b/code/examples/stderr/trait_solver_5.stderr index 230656c..e69de29 100644 --- a/code/examples/stderr/trait_solver_5.stderr +++ b/code/examples/stderr/trait_solver_5.stderr @@ -1,12 +0,0 @@ -error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()` - --> examples/trait_solver_5.rs:6:1 - | -5 | impl> Overlap for U {} - | ----------------------------------- first implementation here -6 | impl Overlap 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 diff --git a/code/examples/trait_solver_5.rs b/code/examples/trait_solver_5.rs index 7b91770..2d0ff86 100644 --- a/code/examples/trait_solver_5.rs +++ b/code/examples/trait_solver_5.rs @@ -1,8 +1,6 @@ -trait Super {} -trait Sub: Super {} +pub trait Super {} +pub trait Sub: Super {} -trait Overlap {} +pub trait Overlap {} impl> Overlap for U {} impl Overlap for () {} - -fn main() {} diff --git a/src/trait_solver/5.md b/src/trait_solver/5.md index fbfab7f..bdfaa71 100644 --- a/src/trait_solver/5.md +++ b/src/trait_solver/5.md @@ -1,4 +1,4 @@ -# Trait Solver 5 @BoxyUwU @WaffleLapkin +# Trait Solver 5 @BoxyUwU @WaffleLapkin @lcnr {{#include ../include/quiz-is-wip.md}} @@ -13,6 +13,8 @@ {{#include ../../code/examples/stderr/trait_solver_5.stderr}} ``` - +In order for these impls to overlap the type `()` must implement `Sub` for some type `T`, the `Sub` trait is public so in theory some downstream crate could implement `(): Sub`. 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.