2020-01-13 15:13:12 -06:00
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
|
LL | fn fuz() -> (usize, Trait) { (42, Struct) }
2020-01-14 15:18:06 -06:00
| ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
2020-01-13 15:13:12 -06:00
|
= note: expected trait object `(dyn Trait + 'static)`
found struct `Struct`
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) }
2020-01-13 19:19:52 -06:00
| ^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
| |
| doesn't have a size known at compile-time
2020-01-13 15:13:12 -06:00
|
2020-09-02 02:40:56 -05:00
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
2020-01-13 15:13:12 -06:00
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
= note: the return type of a function must have a statically known size
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:39
|
LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
2020-01-14 15:18:06 -06:00
| ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
2020-01-13 15:13:12 -06:00
|
= note: expected trait object `(dyn Trait + 'static)`
found struct `Struct`
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:10:13
|
LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
2020-01-13 19:19:52 -06:00
| ^^^^^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
| |
| doesn't have a size known at compile-time
2020-01-13 15:13:12 -06:00
|
2020-09-02 02:40:56 -05:00
= help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
2020-01-13 15:13:12 -06:00
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
= note: the return type of a function must have a statically known size
2020-01-14 15:18:06 -06:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-13 15:13:12 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
|
LL | fn bap() -> Trait { Struct }
| ^^^^^ doesn't have a size known at compile-time
|
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
2020-04-10 12:19:47 -05:00
help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
2020-01-13 15:13:12 -06:00
|
LL | fn bap() -> impl Trait { Struct }
2021-06-21 21:07:19 -05:00
| ~~~~~~~~~~
2020-01-13 15:13:12 -06:00
2020-01-14 15:18:06 -06:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-13 18:12:44 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
2020-01-13 15:13:12 -06:00
|
LL | fn ban() -> dyn Trait { Struct }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
2020-04-10 12:19:47 -05:00
help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
2020-01-13 15:13:12 -06:00
|
LL | fn ban() -> impl Trait { Struct }
2021-06-21 21:07:19 -05:00
| ~~~~~~~~~~
2020-01-13 15:13:12 -06:00
2020-04-10 12:19:47 -05:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-13 18:12:44 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
2020-01-13 15:13:12 -06:00
|
LL | fn bak() -> dyn Trait { unimplemented!() }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2020-04-11 13:31:54 -05:00
help: use `impl Trait` as the return type if all return paths have the same type but you want to expose only the trait in the signature
2020-04-10 12:19:47 -05:00
|
LL | fn bak() -> impl Trait { unimplemented!() }
2021-06-21 21:07:19 -05:00
| ~~~~~~~~~~
2020-04-11 13:31:54 -05:00
help: use a boxed trait object if all return paths implement trait `Trait`
2020-04-10 12:19:47 -05:00
|
LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
2022-04-02 16:22:35 -05:00
| ++++ +
2020-01-13 15:13:12 -06:00
2020-01-14 15:18:06 -06:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-13 18:12:44 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
2020-01-13 15:13:12 -06:00
|
LL | fn bal() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
2020-01-15 13:14:05 -06:00
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
2020-01-14 15:18:06 -06:00
= note: if all the returned values were of the same type you could use `impl Trait` as the return type
2020-01-13 15:13:12 -06:00
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
2020-01-14 15:18:06 -06:00
= note: you can create a new `enum` with a variant for each returned type
2020-01-15 17:49:54 -06:00
help: return a boxed trait object instead
2020-01-15 13:14:05 -06:00
|
2022-04-02 16:22:35 -05:00
LL | fn bal() -> Box<dyn Trait> {
| ++++ +
help: ... and box this value
2020-01-15 13:14:05 -06:00
|
2022-04-02 16:22:35 -05:00
LL | return Box::new(Struct);
| +++++++++ +
help: ... and box this value
|
LL | Box::new(42)
| +++++++++ +
2020-01-13 15:13:12 -06:00
2020-04-11 13:31:54 -05:00
error[E0308]: `if` and `else` have incompatible types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
|
LL | / if true {
LL | | Struct
| | ------ expected because of this
LL | | } else {
LL | | 42
| | ^^ expected struct `Struct`, found integer
LL | | }
| |_____- `if` and `else` have incompatible types
2020-01-24 12:35:13 -06:00
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
|
LL | fn bax() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
= note: if all the returned values were of the same type you could use `impl Trait` as the return type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
= note: you can create a new `enum` with a variant for each returned type
help: return a boxed trait object instead
|
2022-04-02 16:22:35 -05:00
LL | fn bax() -> Box<dyn Trait> {
| ++++ +
help: ... and box this value
|
LL | Box::new(Struct)
| +++++++++ +
help: ... and box this value
2020-01-24 12:35:13 -06:00
|
2022-04-02 16:22:35 -05:00
LL | Box::new(42)
| +++++++++ +
2020-01-24 12:35:13 -06:00
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
2020-01-23 17:21:15 -06:00
|
LL | fn bam() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
LL | if true {
LL | return Struct;
2021-06-28 13:22:47 -05:00
| ^^^^^^ expected struct `Box`, found struct `Struct`
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(Struct);
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
2020-01-23 17:21:15 -06:00
|
LL | fn bam() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
...
LL | 42
2021-06-28 13:22:47 -05:00
| ^^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
2020-01-23 17:21:15 -06:00
|
LL | fn baq() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
LL | if true {
LL | return 0;
2021-06-28 13:22:47 -05:00
| ^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(0);
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
2020-01-23 17:21:15 -06:00
|
LL | fn baq() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
...
LL | 42
2021-06-28 13:22:47 -05:00
| ^^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
2020-01-23 17:21:15 -06:00
|
LL | fn baz() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
LL | if true {
LL | Struct
2021-06-28 13:22:47 -05:00
| ^^^^^^ expected struct `Box`, found struct `Struct`
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(Struct)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
2020-01-23 17:21:15 -06:00
|
LL | fn baz() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
...
LL | 42
2021-06-28 13:22:47 -05:00
| ^^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
2020-01-23 17:21:15 -06:00
|
LL | fn baw() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
LL | if true {
LL | 0
2021-06-28 13:22:47 -05:00
| ^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(0)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
error[E0308]: mismatched types
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
2020-01-23 17:21:15 -06:00
|
LL | fn baw() -> Box<dyn Trait> {
2020-09-02 02:40:56 -05:00
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
2020-01-23 17:21:15 -06:00
...
LL | 42
2021-06-28 13:22:47 -05:00
| ^^ expected struct `Box`, found integer
2020-01-23 17:21:15 -06:00
|
2020-09-02 02:40:56 -05:00
= note: expected struct `Box<(dyn Trait + 'static)>`
2020-01-23 17:21:15 -06: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 13:22:47 -05:00
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
2021-06-21 21:07:19 -05:00
| +++++++++ +
2020-01-23 17:21:15 -06:00
2020-01-14 15:18:06 -06:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
2020-01-13 15:13:12 -06:00
|
LL | fn bat() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
2020-04-10 12:19:47 -05:00
help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
2020-01-13 15:13:12 -06:00
|
LL | fn bat() -> impl Trait {
2021-06-21 21:07:19 -05:00
| ~~~~~~~~~~
2020-01-13 15:13:12 -06:00
2020-01-23 17:21:15 -06:00
error[E0746]: return type cannot have an unboxed trait object
2020-01-24 12:35:13 -06:00
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
2020-01-23 17:21:15 -06:00
|
LL | fn bay() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
2020-04-10 12:19:47 -05:00
help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
2020-01-23 17:21:15 -06:00
|
2020-01-24 12:35:13 -06:00
LL | fn bay() -> impl Trait {
2021-06-21 21:07:19 -05:00
| ~~~~~~~~~~
2020-01-23 17:21:15 -06:00
2020-04-11 13:31:54 -05:00
error: aborting due to 20 previous errors
2020-01-13 15:13:12 -06:00
2020-01-13 19:21:31 -06:00
Some errors have detailed explanations: E0277, E0308, E0746.
2020-01-13 15:13:12 -06:00
For more information about an error, try `rustc --explain E0277`.