-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.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.
Description
trait Trait{
fn func() -> Struct<Self>;
}
struct Struct<T>{
_t: std::marker::PhantomData<*const T>,
}
error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> src/lib.rs:2:18
|
2 | fn func() -> Struct<Self>;
| ^^^^^^^^^^^^- help: consider further restricting `Self`: `where Self: std::marker::Sized`
| |
| doesn't have a size known at compile-time
...
5 | struct Struct<T>{
| - required by this bound in `Struct`
|
= help: the trait `std::marker::Sized` is not implemented for `Self`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
This seems to cause at least some confusion (see #71788)
When adding the "help: the trait std::marker::Sized
is not implemented for Self
",
we can check if the implicit Sized
bound is required for Self
and if not, add
"help: consider relaxing this trait bound" and recommend adding ?Sized
to T
.
estebank
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.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.