I tried this code:
struct Wrap<T: ?Sized>(T);
impl<T: ?Sized> Wrap<T> {
fn foo(self) where Self: Sized {
let a = self.0;
}
}
I expected the code to compile. Instead, I got the following error:
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> src/lib.rs:5:13
|
3 | impl<T: ?Sized> Wrap<T> {
| - this type parameter needs to be `Sized`
4 | fn foo(self) where Self: Sized {
5 | let a = self.0;
| ^ doesn't have a size known at compile-time
|
= note: all local variables must have a statically known size
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
3 - impl<T: ?Sized> Wrap<T> {
3 + impl<T> Wrap<T> {
|
For more information about this error, try `rustc --explain E0277`.
It seems that, to the compiler, Wrap<T>: Sized does not imply T: Sized.
I think that making the compiler do this inference won't cause semver problems, since Sized is a fundamental trait, so changing whether a type implements Sized is already a breaking change.
(Additional context: I was trying to implement a trait for this wrapper type. The trait has a method with a where Self: Sized bound. I ran into this issue while trying to implement this method.)
Meta
Reproducible on the playground with version 1.92.0-nightly (2025-09-16 a9d0a6f15533a364816c)
I tried this code:
I expected the code to compile. Instead, I got the following error:
It seems that, to the compiler,
Wrap<T>: Sizeddoes not implyT: Sized.I think that making the compiler do this inference won't cause semver problems, since Sized is a fundamental trait, so changing whether a type implements Sized is already a breaking change.
(Additional context: I was trying to implement a trait for this wrapper type. The trait has a method with a
where Self: Sizedbound. I ran into this issue while trying to implement this method.)Meta
Reproducible on the playground with version
1.92.0-nightly (2025-09-16 a9d0a6f15533a364816c)