Skip to content

Wrap<T>: Sized should imply T: Sized #146670

@theemathas

Description

@theemathas

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions