pub trait Foo { type Associated; } pub struct X; pub struct Y; impl Foo for X { type Associated = (); } impl Foo for Y { type Associated = (); } impl X { pub fn returns_sized<'a>(&'a self) -> impl Foo + 'a { X } } impl Y { pub fn returns_unsized<'a>(&'a self) -> Box + 'a> { Box::new(X) } }