Commit 283bf92
committed
Point at definition of item with type parameters that couldn't be inferred
When calling a function with type parameters that are unconstrained by the call expression, we mention the type parameter that couldn't be inferred, but the user previously didn't see where the name was coming from. By pointing at the function itself, including the type parameter, we give better context on what they should have done, specially when the inference machinery fails to provide any other context.
```
error[E0282]: type annotations needed
--> $DIR/unresolved_type_param.rs:9:5
|
LL | bar().await;
| ^^^ cannot infer type of the type parameter `T` declared on the function `bar`
|
note: type must be known for this
--> $DIR/unresolved_type_param.rs:6:1
|
LL | async fn bar<T>() -> () {}
| ^^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying the generic argument
|
LL | bar::<T>().await;
| +++++
```
We should further refine when we present this info to make sure we don't provide redundant notes in some cases. Also, there are cases (like those in issue 94969) that don't provide any new information with this change.1 parent 35f1109 commit 283bf92
107 files changed
Lines changed: 656 additions & 5 deletions
File tree
- compiler/rustc_trait_selection/src
- error_reporting/infer
- tests/ui
- array-slice-vec
- associated-type-bounds
- async-await
- closure-expected-type
- closures
- const-generics
- defaults
- generic_const_exprs
- infer
- issues
- consts
- delegation/generics
- error-codes
- for-loop-while
- generic-associated-types
- bugs
- generic-const-items
- impl-trait
- diagnostics
- in-trait
- inference
- need_type_info
- issues
- methods
- missing/missing-items
- parser
- repeat-expr
- return
- span
- suggestions
- types
- trait-bounds
- traits
- next-solver
- type-alias-impl-trait
- type-inference
- typeck
- type
- type-check
- unboxed-closures
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| 128 | + | |
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| 133 | + | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| |||
423 | 426 | | |
424 | 427 | | |
425 | 428 | | |
426 | | - | |
| 429 | + | |
| 430 | + | |
427 | 431 | | |
428 | 432 | | |
429 | 433 | | |
430 | | - | |
| 434 | + | |
431 | 435 | | |
432 | 436 | | |
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
| 440 | + | |
436 | 441 | | |
437 | 442 | | |
438 | 443 | | |
| |||
442 | 447 | | |
443 | 448 | | |
444 | 449 | | |
| 450 | + | |
445 | 451 | | |
446 | 452 | | |
447 | 453 | | |
| |||
451 | 457 | | |
452 | 458 | | |
453 | 459 | | |
| 460 | + | |
454 | 461 | | |
455 | 462 | | |
456 | 463 | | |
| |||
651 | 658 | | |
652 | 659 | | |
653 | 660 | | |
| 661 | + | |
654 | 662 | | |
655 | 663 | | |
656 | 664 | | |
| |||
660 | 668 | | |
661 | 669 | | |
662 | 670 | | |
| 671 | + | |
663 | 672 | | |
664 | 673 | | |
665 | 674 | | |
| |||
669 | 678 | | |
670 | 679 | | |
671 | 680 | | |
| 681 | + | |
672 | 682 | | |
673 | 683 | | |
674 | 684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| |||
214 | 216 | | |
215 | 217 | | |
216 | 218 | | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
| |||
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
| 243 | + | |
| 244 | + | |
239 | 245 | | |
240 | 246 | | |
241 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
7 | 13 | | |
8 | 14 | | |
9 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
0 commit comments