-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant 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.Relevant to the types team, which will review and decide on the PR/issue.
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)
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant 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.Relevant to the types team, which will review and decide on the PR/issue.