help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
|
LL | fn bap() -> impl Trait { Struct }
- | ^^^^^^^^^^
+ | ~~~~~~~~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
|
LL | fn ban() -> impl Trait { Struct }
- | ^^^^^^^^^^
+ | ~~~~~~~~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type
|
LL | fn bak() -> T { unimplemented!() }
- | ^
+ | ~
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
|
LL | fn bak() -> impl Trait { unimplemented!() }
- | ^^^^^^^^^^
+ | ~~~~~~~~~~
help: use a boxed trait object if all return paths implement trait `Trait`
|
LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
- | ^^^^^^^^^^^^^^
+ | ~~~~~~~~~~~~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
= note: you can create a new `enum` with a variant for each returned type
help: return a boxed trait object instead
|
-LL | fn bal() -> Box<dyn Trait> {
+LL ~ fn bal() -> Box<dyn Trait> {
LL | if true {
-LL | return Box::new(Struct);
+LL ~ return Box::new(Struct);
LL | }
-LL | Box::new(42)
+LL ~ Box::new(42)
|
error[E0308]: `if` and `else` have incompatible types
= note: you can create a new `enum` with a variant for each returned type
help: return a boxed trait object instead
|
-LL | fn bax() -> Box<dyn Trait> {
+LL ~ fn bax() -> Box<dyn Trait> {
LL | if true {
-LL | Box::new(Struct)
+LL ~ Box::new(Struct)
LL | } else {
-LL | Box::new(42)
+LL ~ Box::new(42)
|
error[E0308]: mismatched types
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true {
LL | return Struct;
- | ^^^^^^
- | |
- | expected struct `Box`, found struct `Struct`
- | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
+ | ^^^^^^ expected struct `Box`, found struct `Struct`
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | return Box::new(Struct);
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
...
LL | 42
- | ^^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(42)`
+ | ^^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(42)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true {
LL | return 0;
- | ^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(0)`
+ | ^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | return Box::new(0);
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
...
LL | 42
- | ^^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(42)`
+ | ^^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(42)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true {
LL | Struct
- | ^^^^^^
- | |
- | expected struct `Box`, found struct `Struct`
- | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
+ | ^^^^^^ expected struct `Box`, found struct `Struct`
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(Struct)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
...
LL | 42
- | ^^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(42)`
+ | ^^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(42)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true {
LL | 0
- | ^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(0)`
+ | ^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(0)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type
...
LL | 42
- | ^^
- | |
- | expected struct `Box`, found integer
- | help: store this in the heap by calling `Box::new`: `Box::new(42)`
+ | ^^ expected struct `Box`, found integer
|
= note: expected struct `Box<(dyn Trait + 'static)>`
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
+help: store this in the heap by calling `Box::new`
+ |
+LL | Box::new(42)
+ | +++++++++ +
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
|
LL | fn bat() -> impl Trait {
- | ^^^^^^^^^^
+ | ~~~~~~~~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
|
LL | fn bay() -> impl Trait {
- | ^^^^^^^^^^
+ | ~~~~~~~~~~
error: aborting due to 20 previous errors