Closed
Description
trait Trait{
fn func() -> Struct<Self>;
}
struct Struct<T>{
_t: std::marker::PhantomData<*const T>,
}
error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> src/lib.rs:2:18
|
2 | fn func() -> Struct<Self>;
| ^^^^^^^^^^^^- help: consider further restricting `Self`: `where Self: std::marker::Sized`
| |
| doesn't have a size known at compile-time
...
5 | struct Struct<T>{
| - required by this bound in `Struct`
|
= help: the trait `std::marker::Sized` is not implemented for `Self`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
This seems to cause at least some confusion (see #71788)
When adding the "help: the trait std::marker::Sized
is not implemented for Self
",
we can check if the implicit Sized
bound is required for Self
and if not, add
"help: consider relaxing this trait bound" and recommend adding ?Sized
to T
.