Closed
Description
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
, becauseO
by default isSized
. TryO: ?Sized
.