Commit aec9eeb
committed
Do not produce incorrect
```
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/not-on-bare-trait-2021.rs:8:12
|
LL | fn foo(_x: Foo + Send) {
| ^^^^^^^^^^
|
help: use a new generic type parameter, constrained by `Foo + Send`
|
LL | fn foo<T: Foo + Send>(_x: T) {
| +++++++++++++++ ~
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
|
LL | fn foo(_x: impl Foo + Send) {
| ++++
help: alternatively, use a trait object to accept any type that implements `Foo + Send`, accessing its methods at runtime using dynamic dispatch
|
LL | fn foo(_x: &(dyn Foo + Send)) {
| +++++ +
- help: add `dyn` keyword before this trait
- |
- LL | fn foo(_x: dyn Foo + Send) {
- | +++
```dyn Trait suggestion in fn
1 parent f116d4d commit aec9eeb
File tree
2 files changed
+9
-37
lines changed- compiler/rustc_hir_analysis/src/hir_ty_lowering
- tests/ui/traits/bound
2 files changed
+9
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
| 72 | + | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
| |||
212 | 211 | | |
213 | 212 | | |
214 | 213 | | |
215 | | - | |
| 214 | + | |
216 | 215 | | |
217 | | - | |
| 216 | + | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
222 | | - | |
223 | 221 | | |
224 | | - | |
| 222 | + | |
225 | 223 | | |
226 | 224 | | |
227 | 225 | | |
228 | 226 | | |
229 | 227 | | |
230 | 228 | | |
231 | | - | |
232 | | - | |
233 | 229 | | |
234 | 230 | | |
235 | 231 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 232 | + | |
243 | 233 | | |
244 | 234 | | |
245 | 235 | | |
| |||
267 | 257 | | |
268 | 258 | | |
269 | 259 | | |
270 | | - | |
271 | | - | |
272 | | - | |
| 260 | + | |
273 | 261 | | |
274 | | - | |
| 262 | + | |
275 | 263 | | |
276 | 264 | | |
277 | 265 | | |
| |||
293 | 281 | | |
294 | 282 | | |
295 | 283 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | 284 | | |
301 | 285 | | |
302 | 286 | | |
| |||
316 | 300 | | |
317 | 301 | | |
318 | 302 | | |
319 | | - | |
| 303 | + | |
320 | 304 | | |
321 | | - | |
| 305 | + | |
322 | 306 | | |
323 | 307 | | |
324 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
| |||
39 | 35 | | |
40 | 36 | | |
41 | 37 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 38 | | |
47 | 39 | | |
48 | 40 | | |
| |||
58 | 50 | | |
59 | 51 | | |
60 | 52 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 53 | | |
66 | 54 | | |
67 | 55 | | |
| |||
0 commit comments