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
Suggest -> impl Trait and -> Box<dyn Trait> on fn that doesn't return
During development, a function could have a return type set that is a
bare trait object by accident. We already suggest using either a boxed
trait object or `impl Trait` if the return paths will allow it. We now
do so too when there are *no* return paths or they all resolve to `!`.
We still don't handle cases where the trait object is *not* the entirety
of the return type gracefully.
| ^^^^^^^^^ doesn't have a size known at compile-time
74
74
|
75
-
= help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
76
-
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
77
-
= note: the return type of a function must have a statically known size
75
+
= note: currently nothing is being returned, depending on the final implementation you could change the return type in different ways
76
+
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
77
+
= 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>
78
+
help: you could use some type `T` that is `T: Sized` as the return type if all return paths will have the same type
79
+
|
80
+
LL | fn bak() -> T { unimplemented!() }
81
+
| ^
82
+
help: you could use `impl Trait` as the return type if all return paths will have the same type but you want to expose only the trait in the signature
83
+
|
84
+
LL | fn bak() -> impl Trait { unimplemented!() }
85
+
| ^^^^^^^^^^
86
+
help: you could use a boxed trait object if all return paths `impl` trait `Trait`
error[E0277]: the size for values of type `(dyn AbstractRenderer + 'static)` cannot be known at compilation time
1
+
error[E0746]: return type cannot have an unboxed trait object
2
2
--> $DIR/issue-18107.rs:4:5
3
3
|
4
4
LL | dyn AbstractRenderer
5
5
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6
6
|
7
-
= help: the trait `std::marker::Sized` is not implemented for `(dyn AbstractRenderer + 'static)`
8
-
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
9
-
= note: the return type of a function must have a statically known size
7
+
= note: currently nothing is being returned, depending on the final implementation you could change the return type in different ways
8
+
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
9
+
= 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>
10
+
help: you could use some type `T` that is `T: Sized` as the return type if all return paths will have the same type
11
+
|
12
+
LL | T
13
+
|
14
+
help: you could use `impl AbstractRenderer` as the return type if all return paths will have the same type but you want to expose only the trait in the signature
15
+
|
16
+
LL | impl AbstractRenderer
17
+
|
18
+
help: you could use a boxed trait object if all return paths `impl` trait `AbstractRenderer`
19
+
|
20
+
LL | Box<dyn AbstractRenderer>
21
+
|
10
22
11
23
error: aborting due to previous error
12
24
13
-
For more information about this error, try `rustc --explain E0277`.
25
+
For more information about this error, try `rustc --explain E0746`.
0 commit comments