You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| ^^^^^^^^^ doesn't have a size known at compile-time
103
+
|
104
+
= 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>
105
+
= note: if all the returned values were of the same type you could use `impl Trait` as the return type
106
+
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
107
+
= note: you can create a new `enum` with a variant for each returned type
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -112,7 +131,7 @@ LL | return Struct;
112
131
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -128,7 +147,7 @@ LL | 42
128
147
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -144,7 +163,7 @@ LL | return 0;
144
163
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -160,7 +179,7 @@ LL | 42
160
179
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -176,7 +195,7 @@ LL | Struct
176
195
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -192,7 +211,7 @@ LL | 42
192
211
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -208,7 +227,7 @@ LL | 0
208
227
= 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
| -------------- expected `std::boxed::Box<(dyn Trait + 'static)>` because of return type
@@ -224,38 +243,30 @@ LL | 42
224
243
= 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
225
244
226
245
error[E0746]: return type cannot have an unboxed trait object
| ^^^^^^^^^ doesn't have a size known at compile-time
243
262
|
244
-
= 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>
245
-
= note: if all the returned values were of the same type you could use `impl Trait` as the return type
246
263
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
247
-
= note: you can create a new `enum` with a variant for each returned type
248
-
help: return a boxed trait object instead
249
-
|
250
-
LL | fn bay() -> Box<dyn Trait> {
251
-
LL | Box::new(if true {
252
-
LL | 0u32
253
-
LL | } else {
254
-
LL | 42u32
255
-
LL | })
264
+
help: return `impl Trait` instead, as all return paths are of type `u32`, which implements `Trait`
256
265
|
266
+
LL | fn bay() -> impl Trait {
267
+
| ^^^^^^^^^^
257
268
258
-
error: aborting due to 18 previous errors
269
+
error: aborting due to 19 previous errors
259
270
260
271
Some errors have detailed explanations: E0277, E0308, E0746.
261
272
For more information about an error, try `rustc --explain E0277`.
0 commit comments