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
Copy file name to clipboardExpand all lines: src/test/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
+30-31
Original file line number
Diff line number
Diff line change
@@ -236,19 +236,37 @@ error[E0746]: return type cannot have an unboxed trait object
236
236
LL | fn hat() -> dyn std::fmt::Display {
237
237
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
238
238
|
239
-
= 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>
240
-
= note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
241
-
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
242
-
= note: you can create a new `enum` with a variant for each returned type
243
-
help: return a boxed trait object instead
239
+
help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type
244
240
|
245
-
LL ~ fn hat() -> Box<dyn std::fmt::Display> {
246
-
LL | match 13 {
247
-
LL | 0 => {
248
-
LL ~ return Box::new(0i32);
249
-
LL | }
250
-
LL | _ => {
251
-
...
241
+
LL | fn hat() -> T {
242
+
| ~
243
+
help: use `impl std::fmt::Display` as the return type if all return paths have the same type but you want to expose only the trait in the signature
244
+
|
245
+
LL | fn hat() -> impl std::fmt::Display {
246
+
| ~~~~~~~~~~~~~~~~~~~~~~
247
+
help: use a boxed trait object if all return paths implement trait `std::fmt::Display`
248
+
|
249
+
LL | fn hat() -> Box<dyn std::fmt::Display> {
250
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
251
+
252
+
error[E0746]: return type cannot have an unboxed trait object
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
270
-
|
271
-
= 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>
272
-
= note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
273
-
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
274
-
= note: you can create a new `enum` with a variant for each returned type
275
-
help: return a boxed trait object instead
276
-
|
277
-
LL ~ fn pug() -> Box<dyn std::fmt::Display> {
278
-
LL | match 13 {
279
-
LL ~ 0 => Box::new(0i32),
280
-
LL ~ 1 => Box::new(1u32),
281
-
LL ~ _ => Box::new(2u32),
282
-
|
283
-
284
283
error[E0308]: `if` and `else` have incompatible types
0 commit comments