-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support generic function in generate_function
assist
#14065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
/// Returns unique placeholders for types and consts contained in `value`. | ||
pub fn collect_placeholders<T>(value: &T, db: &dyn HirDatabase) -> Vec<TypeOrConstParamId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using petgraph
here seems okay since this doesn't seem to need a lot of graph-like functionaly
r=me with the 2 unwraps replaced |
✌️ @lowr can now approve this pull request |
Two rather random thoughts:
@bors r=Veykril |
☀️ Test successful - checks-actions |
Part of #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 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:
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 withpetgraph
if it's okay to use it though.