This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit eeceba7
committed
Auto merge of rust-lang#14065 - lowr:patch/generate-generic-function, r=Veykril
Support generic function in `generate_function` assist
Part of rust-lang#3639
This PR adds support for generic function generation in `generate_function` assist. Now the assist looks for generic parameters and trait bounds in scope, filters out irrelevant ones, and generates new function with them.
See `fn_generic_params()` for the outline of the procedure, and see comments on `filter_unnecessary_bounds()` for criteria for filtering. I think it's good criteria for most cases, but I'm open to opinions and suggestions.
The diff is pretty big, but it should run in linear time w.r.t. the number of nodes we operate on and should be fast enough.
Some notes:
- When we generate function in an existing impl, generic parameters may cause name conflict. While we can detect the conflict and rename conflicting params, I didn't find it worthwhile mainly because it's really easy to resolve on IDE: use Rename functionality.
- I've implemented graph structure myself, because we don't have graph library as a dependency and we only need the simplest one.
- Although `petgraph` is in our dependency graph and I was initially looking to use it, we don't actually depend on it AFAICT since it's only used in chalk's specialization graph handling, which we don't use. I'd be happy to replace my implementation with `petgraph` if it's okay to use it though.
- There are some caveats that I consider out of scope of this PR. See FIXME notes on added tests.File tree
7 files changed
+980
-64
lines changed- crates
- hir-ty/src
- hir/src
- ide-assists/src/handlers
- ide-db/src
- syntax/src/ast
7 files changed
+980
-64
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
562 | 564 | | |
563 | 565 | | |
564 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2165 | 2165 | | |
2166 | 2166 | | |
2167 | 2167 | | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
2168 | 2178 | | |
2169 | 2179 | | |
2170 | 2180 | | |
| |||
2565 | 2575 | | |
2566 | 2576 | | |
2567 | 2577 | | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
2568 | 2586 | | |
2569 | 2587 | | |
2570 | 2588 | | |
| |||
3144 | 3162 | | |
3145 | 3163 | | |
3146 | 3164 | | |
3147 | | - | |
| 3165 | + | |
3148 | 3166 | | |
3149 | 3167 | | |
3150 | 3168 | | |
3151 | | - | |
| 3169 | + | |
3152 | 3170 | | |
3153 | 3171 | | |
3154 | 3172 | | |
3155 | | - | |
| 3173 | + | |
3156 | 3174 | | |
3157 | 3175 | | |
3158 | 3176 | | |
| |||
3169 | 3187 | | |
3170 | 3188 | | |
3171 | 3189 | | |
3172 | | - | |
| 3190 | + | |
3173 | 3191 | | |
3174 | 3192 | | |
3175 | 3193 | | |
| |||
3604 | 3622 | | |
3605 | 3623 | | |
3606 | 3624 | | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
3607 | 3633 | | |
3608 | 3634 | | |
3609 | 3635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1319 | 1319 | | |
1320 | 1320 | | |
1321 | 1321 | | |
1322 | | - | |
1323 | | - | |
1324 | | - | |
1325 | | - | |
| 1322 | + | |
1326 | 1323 | | |
1327 | 1324 | | |
1328 | 1325 | | |
| |||
1582 | 1579 | | |
1583 | 1580 | | |
1584 | 1581 | | |
1585 | | - | |
| 1582 | + | |
1586 | 1583 | | |
1587 | 1584 | | |
1588 | 1585 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
0 commit comments