Support generic function in generate_function assist#14065
Merged
bors merged 4 commits intorust-lang:masterfrom Feb 2, 2023
Merged
Support generic function in generate_function assist#14065bors merged 4 commits intorust-lang:masterfrom
generate_function assist#14065bors merged 4 commits intorust-lang:masterfrom
Conversation
lowr
commented
Jan 31, 2023
Comment on lines
+623
to
+624
| /// Returns unique placeholders for types and consts contained in `value`. | ||
| pub fn collect_placeholders<T>(value: &T, db: &dyn HirDatabase) -> Vec<TypeOrConstParamId> |
Contributor
Author
There was a problem hiding this comment.
I'm not sure where to place this function. hir_ty::utils says it's for "Helper functions for working with def, which (...) can't be computed directly from *Data" and it doesn't seem to fit there?
Veykril
approved these changes
Feb 1, 2023
Member
Veykril
left a comment
There was a problem hiding this comment.
Not using petgraph here seems okay since this doesn't seem to need a lot of graph-like functionaly
Member
|
r=me with the 2 unwraps replaced |
Contributor
|
✌️ @lowr can now approve this pull request |
Contributor
Author
|
Two rather random thoughts:
@bors r=Veykril |
Contributor
Contributor
Contributor
|
☀️ Test successful - checks-actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3639
This PR adds support for generic function generation in
generate_functionassist. 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 onfilter_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:
petgraphis 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 withpetgraphif it's okay to use it though.