2020-01-13 13:13:12 -08:00
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:13
|
LL | fn fuz() -> (usize, Trait) { (42, Struct) }
2025-01-30 04:23:14 +00:00
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
2020-01-13 13:13:12 -08:00
|
2024-10-24 21:14:17 +00:00
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
2023-11-27 20:25:45 +00:00
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
2020-01-13 13:13:12 -08:00
= note: the return type of a function must have a statically known size
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:11:13
2020-01-13 13:13:12 -08:00
|
LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
2025-01-30 04:23:14 +00:00
| ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
2020-01-13 13:13:12 -08:00
|
2024-10-24 21:14:17 +00:00
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
2023-11-27 20:25:45 +00:00
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
2020-01-13 13:13:12 -08:00
= note: the return type of a function must have a statically known size
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
2020-01-13 13:13:12 -08:00
|
LL | fn bap() -> Trait { Struct }
| ^^^^^ doesn't have a size known at compile-time
|
2024-07-19 19:39:37 +00:00
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
LL | fn bap() -> impl Trait { Struct }
| ++++
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
2020-01-13 13:13:12 -08:00
|
2024-07-19 19:39:37 +00:00
LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) }
| +++++++ + +++++++++ +
2020-01-13 13:13:12 -08:00
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
2020-01-13 13:13:12 -08:00
|
LL | fn ban() -> dyn Trait { Struct }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2024-07-19 19:39:37 +00:00
help: consider returning an `impl Trait` instead of a `dyn Trait`
2020-01-13 13:13:12 -08:00
|
2024-07-09 22:30:26 +00:00
LL - fn ban() -> dyn Trait { Struct }
LL + fn ban() -> impl Trait { Struct }
|
2024-07-19 19:39:37 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
2023-05-18 01:47:55 +00:00
|
LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
| ++++ + +++++++++ +
2020-01-13 13:13:12 -08:00
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
2020-01-13 13:13:12 -08:00
|
LL | fn bak() -> dyn Trait { unimplemented!() }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2024-07-19 19:39:37 +00:00
help: consider returning an `impl Trait` instead of a `dyn Trait`
2020-04-10 10:19:47 -07:00
|
2024-07-09 22:30:26 +00:00
LL - fn bak() -> dyn Trait { unimplemented!() }
LL + fn bak() -> impl Trait { unimplemented!() }
|
2024-07-19 19:39:37 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
2020-04-10 10:19:47 -07:00
|
2023-05-18 01:47:55 +00:00
LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
| ++++ + +++++++++ +
2020-01-13 13:13:12 -08:00
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:21:13
2020-01-13 13:13:12 -08:00
|
LL | fn bal() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2025-01-30 04:23:14 +00:00
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
2024-07-09 22:30:26 +00:00
LL - fn bal() -> dyn Trait {
LL + fn bal() -> impl Trait {
|
2025-01-30 04:23:14 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
2020-01-15 11:14:05 -08:00
|
2023-05-18 01:47:55 +00:00
LL ~ fn bal() -> Box<dyn Trait> {
LL | if true {
LL ~ return Box::new(Struct);
LL | }
LL ~ Box::new(42)
2022-04-02 14:22:35 -07:00
|
2020-01-13 13:13:12 -08:00
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:27:13
2020-01-24 10:35:13 -08:00
|
LL | fn bax() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2025-01-30 04:23:14 +00:00
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
2024-07-09 22:30:26 +00:00
LL - fn bax() -> dyn Trait {
LL + fn bax() -> impl Trait {
|
2025-01-30 04:23:14 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
2022-04-02 14:22:35 -07:00
|
2023-05-18 01:47:55 +00:00
LL ~ fn bax() -> Box<dyn Trait> {
LL | if true {
LL ~ Box::new(Struct)
LL | } else {
LL ~ Box::new(42)
2020-01-24 10:35:13 -08:00
|
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:62:13
|
LL | fn bat() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
2024-07-09 22:30:26 +00:00
LL - fn bat() -> dyn Trait {
LL + fn bat() -> impl Trait {
|
2025-01-30 04:23:14 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
|
LL ~ fn bat() -> Box<dyn Trait> {
LL | if true {
LL ~ return Box::new(0);
LL | }
LL ~ Box::new(42)
|
2025-02-02 14:58:12 +00:00
error[E0746]: return type cannot be a trait object without pointer indirection
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:68:13
|
LL | fn bay() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
help: consider returning an `impl Trait` instead of a `dyn Trait`
|
2024-07-09 22:30:26 +00:00
LL - fn bay() -> dyn Trait {
LL + fn bay() -> impl Trait {
|
2025-01-30 04:23:14 +00:00
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
|
LL ~ fn bay() -> Box<dyn Trait> {
LL | if true {
LL ~ Box::new(0)
LL | } else {
LL ~ Box::new(42)
|
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
|
LL | fn fuz() -> (usize, Trait) { (42, Struct) }
| ^^^^^^ expected `dyn Trait`, found `Struct`
|
= note: expected trait object `(dyn Trait + 'static)`
found struct `Struct`
= help: `Struct` implements `Trait` so you could box the found value and coerce it to the trait object `Box<dyn Trait>`, you will have to change the expected type as well
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:30
|
LL | fn fuz() -> (usize, Trait) { (42, Struct) }
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
= note: tuples must have a statically known size to be initialized
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:11:39
|
LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
| ^^^^^^ expected `dyn Trait`, found `Struct`
|
= note: expected trait object `(dyn Trait + 'static)`
found struct `Struct`
= help: `Struct` implements `Trait` so you could box the found value and coerce it to the trait object `Box<dyn Trait>`, you will have to change the expected type as well
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:11:34
|
LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
= note: tuples must have a statically known size to be initialized
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:16
2020-01-23 15:21:15 -08:00
|
LL | fn bam() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
LL | if true {
LL | return Struct;
2023-01-02 18:00:33 -08:00
| ^^^^^^ expected `Box<dyn Trait>`, found `Struct`
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found struct `Struct`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(Struct);
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:38:5
2020-01-23 15:21:15 -08:00
|
LL | fn bam() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
...
LL | 42
2023-01-02 18:00:33 -08:00
| ^^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:16
2020-01-23 15:21:15 -08:00
|
LL | fn baq() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
LL | if true {
LL | return 0;
2023-01-02 18:00:33 -08:00
| ^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(0);
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:44:5
2020-01-23 15:21:15 -08:00
|
LL | fn baq() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
...
LL | 42
2023-01-02 18:00:33 -08:00
| ^^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
2020-01-23 15:21:15 -08:00
|
LL | fn baz() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
LL | if true {
LL | Struct
2023-01-02 18:00:33 -08:00
| ^^^^^^ expected `Box<dyn Trait>`, found `Struct`
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found struct `Struct`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(Struct)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:50:9
2020-01-23 15:21:15 -08:00
|
LL | fn baz() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
...
LL | 42
2023-01-02 18:00:33 -08:00
| ^^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
2020-01-23 15:21:15 -08:00
|
LL | fn baw() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
LL | if true {
LL | 0
2023-01-02 18:00:33 -08:00
| ^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(0)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
error[E0308]: mismatched types
2025-01-30 04:23:14 +00:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:57:9
2020-01-23 15:21:15 -08:00
|
LL | fn baw() -> Box<dyn Trait> {
2020-09-02 10:40:56 +03:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 15:21:15 -08:00
...
LL | 42
2023-01-02 18:00:33 -08:00
| ^^ expected `Box<dyn Trait>`, found integer
2020-01-23 15:21:15 -08:00
|
2020-09-02 10:40:56 +03:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 15:21:15 -08:00
found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
2021-06-28 11:22:47 -07:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 19:07:19 -07:00
| +++++++++ +
2020-01-23 15:21:15 -08:00
2025-01-30 04:23:14 +00:00
error: aborting due to 21 previous errors
2020-01-13 13:13:12 -08:00
2020-01-13 17:21:31 -08:00
Some errors have detailed explanations: E0277, E0308, E0746.
2020-01-13 13:13:12 -08:00
For more information about an error, try `rustc --explain E0277`.