@@ -48,22 +48,26 @@ error[E0746]: return type cannot have an unboxed trait object
4848LL | fn bap() -> Trait { Struct }
4949 | ^^^^^ doesn't have a size known at compile-time
5050 |
51- help: box the return type, and wrap all of the returned values in `Box::new`
51+ help: consider returning an `impl Trait` instead of a `dyn Trait`
52+ |
53+ LL | fn bap() -> impl Trait { Struct }
54+ | ++++
55+ help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
5256 |
53- LL | fn bap() -> Box<Trait> { Box::new(Struct) }
54- | ++++ + +++++++++ +
57+ LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) }
58+ | +++++++ + +++++++++ +
5559
5660error[E0746]: return type cannot have an unboxed trait object
5761 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
5862 |
5963LL | fn ban() -> dyn Trait { Struct }
6064 | ^^^^^^^^^ doesn't have a size known at compile-time
6165 |
62- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
66+ help: consider returning an `impl Trait` instead of a `dyn Trait`
6367 |
6468LL | fn ban() -> impl Trait { Struct }
6569 | ~~~~
66- help: box the return type, and wrap all of the returned values in `Box::new`
70+ help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
6771 |
6872LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
6973 | ++++ + +++++++++ +
@@ -74,11 +78,11 @@ error[E0746]: return type cannot have an unboxed trait object
7478LL | fn bak() -> dyn Trait { unimplemented!() }
7579 | ^^^^^^^^^ doesn't have a size known at compile-time
7680 |
77- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
81+ help: consider returning an `impl Trait` instead of a `dyn Trait`
7882 |
7983LL | fn bak() -> impl Trait { unimplemented!() }
8084 | ~~~~
81- help: box the return type, and wrap all of the returned values in `Box::new`
85+ help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
8286 |
8387LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
8488 | ++++ + +++++++++ +
@@ -89,10 +93,7 @@ error[E0746]: return type cannot have an unboxed trait object
8993LL | fn bal() -> dyn Trait {
9094 | ^^^^^^^^^ doesn't have a size known at compile-time
9195 |
92- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
93- |
94- LL | fn bal() -> impl Trait {
95- | ~~~~
96+ = help: if there were a single returned type, you could use `impl Trait` instead
9697help: box the return type, and wrap all of the returned values in `Box::new`
9798 |
9899LL ~ fn bal() -> Box<dyn Trait> {
@@ -108,10 +109,7 @@ error[E0746]: return type cannot have an unboxed trait object
108109LL | fn bax() -> dyn Trait {
109110 | ^^^^^^^^^ doesn't have a size known at compile-time
110111 |
111- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
112- |
113- LL | fn bax() -> impl Trait {
114- | ~~~~
112+ = help: if there were a single returned type, you could use `impl Trait` instead
115113help: box the return type, and wrap all of the returned values in `Box::new`
116114 |
117115LL ~ fn bax() -> Box<dyn Trait> {
@@ -263,10 +261,7 @@ error[E0746]: return type cannot have an unboxed trait object
263261LL | fn bat() -> dyn Trait {
264262 | ^^^^^^^^^ doesn't have a size known at compile-time
265263 |
266- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
267- |
268- LL | fn bat() -> impl Trait {
269- | ~~~~
264+ = help: if there were a single returned type, you could use `impl Trait` instead
270265help: box the return type, and wrap all of the returned values in `Box::new`
271266 |
272267LL ~ fn bat() -> Box<dyn Trait> {
@@ -282,10 +277,7 @@ error[E0746]: return type cannot have an unboxed trait object
282277LL | fn bay() -> dyn Trait {
283278 | ^^^^^^^^^ doesn't have a size known at compile-time
284279 |
285- help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
286- |
287- LL | fn bay() -> impl Trait {
288- | ~~~~
280+ = help: if there were a single returned type, you could use `impl Trait` instead
289281help: box the return type, and wrap all of the returned values in `Box::new`
290282 |
291283LL ~ fn bay() -> Box<dyn Trait> {
0 commit comments