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
Rollup merge of rust-lang#120164 - trevyn:is_downgradable, r=compiler-errors
`maybe_lint_impl_trait`: separate `is_downgradable` from `is_object_safe`
rust-lang#119752 leveraged and overloaded `is_object_safe` to prevent an ICE, but accurate object safety information is needed for precise suggestions. This separates out `is_downgradable`, used for the ICE prevention, and `is_object_safe`, which returns to its original meaning.
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
| help: consider changing method `f`'s `self` parameter to be `&self` (notice the capitalization): `&Self`
83
+
|
84
+
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
= note: `B` it is not object safe, so it can't be `dyn`
103
126
help: use a new generic type parameter, constrained by `B`
104
127
|
105
-
LL | fn f<T: B>(a: T) -> B;
128
+
LL | fn f<T: B>(b: T) -> B;
106
129
| ++++++ ~
107
130
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
108
131
|
109
-
LL | fn f(a: impl B) -> B;
110
-
| ++++
111
-
help: alternatively, use a trait object to accept any type that implements `B`, accessing its methods at runtime using dynamic dispatch
112
-
|
113
-
LL | fn f(a: &dyn B) -> B;
132
+
LL | fn f(b: impl B) -> B;
114
133
| ++++
115
134
116
135
error[E0782]: trait objects must include the `dyn` keyword
= note: `C` it is not object safe, so it can't be `dyn`
137
153
help: use a new generic type parameter, constrained by `C`
138
154
|
139
-
LL | fn f<T: C>(&self, a: T) -> C;
155
+
LL | fn f<T: C>(&self, c: T) -> C;
140
156
| ++++++ ~
141
157
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
142
158
|
143
-
LL | fn f(&self, a: impl C) -> C;
144
-
| ++++
145
-
help: alternatively, use a trait object to accept any type that implements `C`, accessing its methods at runtime using dynamic dispatch
146
-
|
147
-
LL | fn f(&self, a: &dyn C) -> C;
159
+
LL | fn f(&self, c: impl C) -> C;
148
160
| ++++
149
161
150
162
error[E0782]: trait objects must include the `dyn` keyword
0 commit comments