|
| 1 | +error[E0746]: return type cannot have an unboxed trait object |
| 2 | + --> $DIR/unsized-return.rs:3:13 |
| 3 | + | |
| 4 | +LL | fn foo() -> dyn T { |
| 5 | + | ^^^^^ doesn't have a size known at compile-time |
| 6 | + | |
| 7 | + = help: if the returned value came from a borrowed argument that implements the trait, then you could return `&dyn Trait` |
| 8 | +help: return an `impl Trait` instead of a `dyn Trait` |
| 9 | + | |
| 10 | +LL | fn foo() -> impl T { |
| 11 | + | ~~~~ |
| 12 | +help: alternatively, box the return type to make a boxed trait object, and wrap all of the returned values in `Box::new` |
| 13 | + | |
| 14 | +LL ~ fn foo() -> Box<dyn T> { |
| 15 | +LL ~ Box::new(todo!()) |
| 16 | + | |
| 17 | + |
| 18 | +error[E0277]: the size for values of type `dyn T` cannot be known at compilation time |
| 19 | + --> $DIR/unsized-return.rs:10:12 |
| 20 | + | |
| 21 | +LL | let x: dyn T = foo(); |
| 22 | + | ^^^^^ doesn't have a size known at compile-time |
| 23 | + | |
| 24 | + = help: the trait `Sized` is not implemented for `dyn T` |
| 25 | + = note: all local variables must have a statically known size |
| 26 | + = help: unsized locals are gated as an unstable feature |
| 27 | +help: consider borrowing here |
| 28 | + | |
| 29 | +LL | let x: &dyn T = foo(); |
| 30 | + | + |
| 31 | + |
| 32 | +error[E0277]: the size for values of type `dyn T` cannot be known at compilation time |
| 33 | + --> $DIR/unsized-return.rs:8:13 |
| 34 | + | |
| 35 | +LL | let x = foo(); |
| 36 | + | ^^^^^ doesn't have a size known at compile-time |
| 37 | + | |
| 38 | + = help: the trait `Sized` is not implemented for `dyn T` |
| 39 | + = note: all local variables must have a statically known size |
| 40 | + = help: unsized locals are gated as an unstable feature |
| 41 | + |
| 42 | +error[E0277]: the size for values of type `(dyn T + 'static)` cannot be known at compilation time |
| 43 | + --> $DIR/unsized-return.rs:8:13 |
| 44 | + | |
| 45 | +LL | let x = foo(); |
| 46 | + | ^^^^^ doesn't have a size known at compile-time |
| 47 | + | |
| 48 | + = help: the trait `Sized` is not implemented for `(dyn T + 'static)` |
| 49 | + = note: the return type of a function must have a statically known size |
| 50 | + |
| 51 | +error: aborting due to 4 previous errors |
| 52 | + |
| 53 | +Some errors have detailed explanations: E0277, E0746. |
| 54 | +For more information about an error, try `rustc --explain E0277`. |
0 commit comments