-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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
Given the following code: (playground)
trait TraitWithAType {
type Item;
}
trait Trait {}
struct A {}
impl TraitWithAType for A {
type Item = dyn Trait;
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> src/lib.rs:7:5
|
2 | type Item;
| ---------- required by this bound in `TraitWithAType::Item`
...
7 | type Item = dyn Trait;
| ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Ideally the output should look like:
|
2 | type Item;
| ---------- required by this bound in `TraitWithAType::Item`
...
7 | type Item = dyn Trait;
| ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
help: consider relaxing the implicit `Sized` restriction
|
2 | type Item: ?Sized
| ^^^^^^^^
A similar error message with an unsized generic type argument does mention the implicit Sized
bound. (playground) Unfortunately, it also doesn't explain the implicit bound up front in the "required by this bound" text. (It mentions it when suggesting to relax the implicit bound, but I think it would be better to mention it up front as well.)
Both error messages could benefit from changing the "required by this bound" text to "required by an implicit Sized
bound".
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemA-type-systemArea: Type systemArea: Type systemD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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.