Repository navigation
Too many dyn Trait is not Sized errors #105753
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-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
When writing
trait T {}
fn foo() -> dyn T {
todo!()
}
fn main() {
let x = foo();
}We emit three errors for dyn T: Sized not being fulfilled. We should likely only emit 1, in foo's return type, but we certainly shouldn't be emitting both one for x and one for foo's call.
error[E0746]: return type cannot have an unboxed trait object
--> src/main.rs:3:13
|
3 | fn foo() -> dyn T {
| ^^^^^ doesn't have a size known at compile-time
|
help: use `impl T` as the return type if all return paths have the same type but you want to expose only the trait in the signature
|
3 | fn foo() -> impl T {
| ~~~~~~
help: use a boxed trait object if all return paths implement trait `T`
|
3 | fn foo() -> Box<dyn T> {
| ++++ +
error[E0277]: the size for values of type `dyn T` cannot be known at compilation time
--> src/main.rs:8:9
|
8 | let x = foo();
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn T`
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
error[E0277]: the size for values of type `(dyn T + 'static)` cannot be known at compilation time
--> src/main.rs:8:13
|
8 | let x = foo();
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn T + 'static)`
= note: the return type of a function must have a statically known size
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-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.
Activity
eopb commentedon Dec 23, 2022
@rustbot claim
eopb commentedon Jan 9, 2023
I found working on this issue a little too challenging. I don't think I'll be able to get any further without guidance.
@rustbot release-assignment
Ezrashaw commentedon Jan 11, 2023
Hmm, I might work on this but I only want to remove the third error. The other two make sense to me: you can't return a unsized value and you can't assign a unsized value to a local variable.
@rustbot claim
Rollup merge of rust-lang#163913 - estebank:wellformedloc, r=oli-obk
Rollup merge of rust-lang#163913 - estebank:wellformedloc, r=oli-obk
Unrolled build for #163913 in rollup 164005
Rollup merge of #163913 - estebank:wellformedloc, r=oli-obk