@@ -48,22 +48,26 @@ error[E0746]: return type cannot have an unboxed trait object
48
48
LL | fn bap() -> Trait { Struct }
49
49
| ^^^^^ doesn't have a size known at compile-time
50
50
|
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`
52
56
|
53
- LL | fn bap() -> Box<Trait> { Box::new(Struct) }
54
- | ++++ + +++++++++ +
57
+ LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) }
58
+ | +++++++ + +++++++++ +
55
59
56
60
error[E0746]: return type cannot have an unboxed trait object
57
61
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
58
62
|
59
63
LL | fn ban() -> dyn Trait { Struct }
60
64
| ^^^^^^^^^ doesn't have a size known at compile-time
61
65
|
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`
63
67
|
64
68
LL | fn ban() -> impl Trait { Struct }
65
69
| ~~~~
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`
67
71
|
68
72
LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
69
73
| ++++ + +++++++++ +
@@ -74,11 +78,11 @@ error[E0746]: return type cannot have an unboxed trait object
74
78
LL | fn bak() -> dyn Trait { unimplemented!() }
75
79
| ^^^^^^^^^ doesn't have a size known at compile-time
76
80
|
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`
78
82
|
79
83
LL | fn bak() -> impl Trait { unimplemented!() }
80
84
| ~~~~
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`
82
86
|
83
87
LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
84
88
| ++++ + +++++++++ +
@@ -89,10 +93,7 @@ error[E0746]: return type cannot have an unboxed trait object
89
93
LL | fn bal() -> dyn Trait {
90
94
| ^^^^^^^^^ doesn't have a size known at compile-time
91
95
|
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
96
97
help: box the return type, and wrap all of the returned values in `Box::new`
97
98
|
98
99
LL ~ fn bal() -> Box<dyn Trait> {
@@ -108,10 +109,7 @@ error[E0746]: return type cannot have an unboxed trait object
108
109
LL | fn bax() -> dyn Trait {
109
110
| ^^^^^^^^^ doesn't have a size known at compile-time
110
111
|
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
115
113
help: box the return type, and wrap all of the returned values in `Box::new`
116
114
|
117
115
LL ~ fn bax() -> Box<dyn Trait> {
@@ -263,10 +261,7 @@ error[E0746]: return type cannot have an unboxed trait object
263
261
LL | fn bat() -> dyn Trait {
264
262
| ^^^^^^^^^ doesn't have a size known at compile-time
265
263
|
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
270
265
help: box the return type, and wrap all of the returned values in `Box::new`
271
266
|
272
267
LL ~ fn bat() -> Box<dyn Trait> {
@@ -282,10 +277,7 @@ error[E0746]: return type cannot have an unboxed trait object
282
277
LL | fn bay() -> dyn Trait {
283
278
| ^^^^^^^^^ doesn't have a size known at compile-time
284
279
|
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
289
281
help: box the return type, and wrap all of the returned values in `Box::new`
290
282
|
291
283
LL ~ fn bay() -> Box<dyn Trait> {
0 commit comments