This compiles:
pub trait MyTrait { fn do_it(&self) -> &i32; } impl AsRef<i32> for dyn MyTrait { fn as_ref(&self) -> &i32 { self.do_it() } } It compiles even though AsRef is foreign, because the orphan rules consider dyn T to be local if T is local, but I can't find any spec that allows it.
This does not compile:
pub struct S{ pub v: i32 } impl std::hash::Hash for dyn AsRef<S> { fn hash<H>(&self, state: &mut H) where H: std::hash::Hasher { state.write_i32(self.as_ref().v) } } It does not compile, because dyn AsRef<S> is not considered local, even though S is local.
Where is the spec that allows the first one, but not the second?
2 posts - 2 participants

