Trait Solver 3 @BoxyUwU @WaffleLapkin
Warning: this quiz is still "work-in-progress", some questions might not have good explanations (or any at all), formatting/structure/titles/etc are not final, and so on. You might want to return here on a later date.
trait TraitA {}
trait TraitB<T: Sized> {}
impl TraitA for &dyn TraitB<[u8]> {}
trait MyDefault {
fn default() -> Self;
}
impl<T: TraitA> MyDefault for T {
fn default() -> T {
todo!("not important for the example")
}
}
fn main() {
<&dyn TraitB<[u8]> as MyDefault>::default();
}
Solution
thread 'main' panicked at examples/trait_solver_3.rs:12:9:
not yet implemented: not important for the example
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Yeah. This actually runs.
(:
The compiler does not check "Well Formedness" of traits in trait objects, so dyn Trait<[u8]>
does not produce an error, even though [u8]
is not Sized
.
This is might be unsound, but no one come up with an example of causing UB in safe code with this. At the very least, this is unexpected.