rust-lang / rust-lang/rust

`Wrap<T>: Sized` should imply `T: Sized`

Open
#146,670 2 comments 0 reactions 1 assignee View on GitHub

@sgasho is already working on this.

Since Oct 19, 2025.

A-trait-system A-type-system C-enhancement needs-fcp T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.