Skip to content

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

Open

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)

Activity

  1. added
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Sep 17, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 17, 2025
  3. theemathas commented on Sep 17, 2025

    @theemathas
    ContributorAuthor

    Note that Sized already has some special behavior similar to this, such as #135480

  4. added
    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.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 17, 2025
  5. sgasho commented on Oct 19, 2025

    @sgasho
    Contributor

    @rustbot claim

  6. added
    needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.
    and removed
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions