I was not aware that Sized is a default requirement for type parameters, so I was very confused why this code doesn't compile:
trait OopsSized<O /* missing : ?Sized */> {
fn foo(&self) -> Option<Box<O>>;
}
trait Unsized {}
struct Foo;
impl OopsSized<Unsized> for Foo {
fn foo(&self) -> Option<Box<Unsized>> {
None
}
}
I couldn't understand why compiler insists on having Sized for the innermost type, if Box doesn't care and makes the boxed type sized.
The current explanation for E0277 doesn't cover this case specifically, and it doesn't mention the unusual ?Sized syntax. It'd help me if, for example, the hint:
note: required by OopsSized
made implied defaults explicitly spelled out:
note: required by OopsSized<O: Sized>
and/or hinted how to fix it:
note: required by OopsSized, because O by default is Sized. Try O: ?Sized.
I was not aware that
Sizedis a default requirement for type parameters, so I was very confused why this code doesn't compile:I couldn't understand why compiler insists on having
Sizedfor the innermost type, ifBoxdoesn't care and makes the boxed type sized.The current explanation for E0277 doesn't cover this case specifically, and it doesn't mention the unusual
?Sizedsyntax. It'd help me if, for example, the hint:made implied defaults explicitly spelled out:
and/or hinted how to fix it: