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 | if true {
-LL ~ return Box::new(Struct);
-LL | }
-LL ~ Box::new(42)
+LL | fn bal() -> Box<dyn Trait> {
+ | ++++ +
+help: ... and box this value
+ |
+LL | return Box::new(Struct);
+ | +++++++++ +
+help: ... and box this value
|
+LL | Box::new(42)
+ | +++++++++ +
error[E0308]: `if` and `else` have incompatible types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
= 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 | if true {
-LL ~ Box::new(Struct)
-LL | } else {
-LL ~ Box::new(42)
+LL | fn bax() -> Box<dyn Trait> {
+ | ++++ +
+help: ... and box this value
+ |
+LL | Box::new(Struct)
+ | +++++++++ +
+help: ... and box this value
|
+LL | Box::new(42)
+ | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16