Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many dyn Trait is not Sized errors #105753

Open
estebank opened this issue Dec 15, 2022 · 3 comments · May be fixed by #122957
Open

Too many dyn Trait is not Sized errors #105753

estebank opened this issue Dec 15, 2022 · 3 comments · May be fixed by #122957
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Dec 15, 2022

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
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Dec 15, 2022
@eopb
Copy link
Contributor

eopb commented Dec 23, 2022

@rustbot claim

@eopb
Copy link
Contributor

eopb commented 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

@rustbot rustbot unassigned eopb Jan 9, 2023
@Ezrashaw
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants