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
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
19
-
--> $DIR/not-on-bare-trait-2021.rs:12:11
19
+
--> $DIR/not-on-bare-trait-2021.rs:11:11
20
20
|
21
21
LL | fn bar(x: Foo) -> Foo {
22
22
| ^^^ doesn't have a size known at compile-time
@@ -32,60 +32,79 @@ help: function arguments must have a statically known size, borrowed types alway
32
32
LL | fn bar(x: &dyn Foo) -> Foo {
33
33
| ++++
34
34
35
-
error[E0782]: trait objects must include the `dyn` keyword
36
-
--> $DIR/not-on-bare-trait-2021.rs:8:12
35
+
error[E0746]: return type cannot have an unboxed trait object
36
+
--> $DIR/not-on-bare-trait-2021.rs:15:20
37
37
|
38
-
LL | fn foo(_x: Foo + Send) {
39
-
| ^^^^^^^^^^
38
+
LL | fn bat(x: &Foo) -> Foo {
39
+
| ^^^ doesn't have a size known at compile-time
40
40
|
41
-
help: use a new generic type parameter, constrained by `Foo + Send`
41
+
help: return an `impl Trait` instead of a `dyn Trait`
42
42
|
43
-
LL | fn foo<T: Foo + Send>(_x: T) {
44
-
| +++++++++++++++~
45
-
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
43
+
LL | fn bat(x: &Foo) -> impl Foo {
44
+
| ++++
45
+
help: alternatively, box the return type to make a boxed trait object, and wrap all of the returned values in `Box::new`
46
46
|
47
-
LL | fn foo(_x: impl Foo + Send) {
48
-
| ++++
49
-
help: alternatively, use a trait object to accept any type that implements `Foo + Send`, accessing its methods at runtime using dynamic dispatch
47
+
LL ~ fn bat(x: &Foo) -> Box<dyn Foo> {
48
+
LL |
49
+
LL |
50
+
LL ~ Box::new(x)
50
51
|
51
-
LL | fn foo(_x: &(dyn Foo + Send)) {
52
-
| +++++ +
52
+
help: finally, you might be able to borrow from the function's argument
53
+
|
54
+
LL | fn bat(x: &Foo) -> &dyn Foo {
55
+
| ++++
53
56
54
-
error[E0782]: trait objects must include the `dyn` keyword
55
-
--> $DIR/not-on-bare-trait-2021.rs:12:11
57
+
error[E0746]: return type cannot have an unboxed trait object
58
+
--> $DIR/not-on-bare-trait-2021.rs:25:13
56
59
|
57
-
LL | fn bar(x: Foo) -> Foo {
58
-
| ^^^
60
+
LL | fn qux() -> Foo {
61
+
| ^^^ doesn't have a size known at compile-time
59
62
|
60
-
help: use a new generic type parameter, constrained by `Foo`
63
+
help: return an `impl Trait` instead of a `dyn Trait`
61
64
|
62
-
LL | fn bar<T: Foo>(x: T) -> Foo {
63
-
| ++++++++~
64
-
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
65
+
LL | fn qux() -> impl Foo {
66
+
| ++++
67
+
help: alternatively, box the return type to make a boxed trait object, and wrap all of the returned values in `Box::new`
65
68
|
66
-
LL | fn bar(x: impl Foo) -> Foo {
67
-
| ++++
68
-
help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch
69
+
LL ~ fn qux() -> Box<dyn Foo> {
70
+
LL |
71
+
LL ~ Box::new(todo!())
69
72
|
70
-
LL | fn bar(x: &dyn Foo) -> Foo {
71
-
| ++++
72
73
73
74
error[E0782]: trait objects must include the `dyn` keyword
74
-
--> $DIR/not-on-bare-trait-2021.rs:12:19
75
+
--> $DIR/not-on-bare-trait-2021.rs:15:12
75
76
|
76
-
LL | fn bar(x: Foo) -> Foo {
77
-
| ^^^
77
+
LL | fn bat(x: &Foo) -> Foo {
78
+
| ^^^
79
+
|
80
+
help: add `dyn` keyword before this trait
81
+
|
82
+
LL | fn bat(x: &dyn Foo) -> Foo {
83
+
| +++
84
+
85
+
error[E0782]: trait objects must include the `dyn` keyword
86
+
--> $DIR/not-on-bare-trait-2021.rs:20:12
87
+
|
88
+
LL | fn bae(x: &Foo) -> &Foo {
89
+
| ^^^
90
+
|
91
+
help: add `dyn` keyword before this trait
92
+
|
93
+
LL | fn bae(x: &dyn Foo) -> &Foo {
94
+
| +++
95
+
96
+
error[E0782]: trait objects must include the `dyn` keyword
97
+
--> $DIR/not-on-bare-trait-2021.rs:20:21
78
98
|
79
-
help: use `impl Foo` to return an opaque type, as long as you return a single underlying type
99
+
LL | fn bae(x: &Foo) -> &Foo {
100
+
| ^^^
80
101
|
81
-
LL | fn bar(x: Foo) -> impl Foo {
82
-
| ++++
83
-
help: alternatively, you can return a boxed trait object
102
+
help: add `dyn` keyword before this trait
84
103
|
85
-
LL | fn bar(x: Foo) -> Box<dyn Foo> {
86
-
| +++++++ +
104
+
LL | fn bae(x: &Foo) -> &dyn Foo {
105
+
| +++
87
106
88
-
error: aborting due to 5 previous errors
107
+
error: aborting due to 7 previous errors
89
108
90
-
Some errors have detailed explanations: E0277, E0782.
109
+
Some errors have detailed explanations: E0277, E0746, E0782.
91
110
For more information about an error, try `rustc --explain E0277`.
0 commit comments