You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change attempts to resolve issue rust-lang#7637: Extract into Function does not
create a generic function with constraints when extracting generic code.
In `FunctionBody::analyze_container`, when the ancestor matches `ast::Fn`, we
can perserve both the `generic_param_list` and the `where_clause`. These can
then be included in the newly extracted function output via `format_function`.
From what I can tell, the only other ancestor type that could potentially have
a generic param list would be `ast::ClosureExpr`. In this case, we perserve the
`generic_param_list`, but no where clause is ever present.
In this inital implementation, all the generic params and where clauses from
the parent function will be copied to the newly extracted function. An obvious
improvement would be to filter this output in some way to only include generic
parameters that are actually used in the function body. I'm not experienced
enough with this codebase to know how challenging doing this kind of filtration
would be.
I don't believe this implementation will work in contexts where the generic
parameters and where clauses are defined multiple layers above the function
being extracted, such as with nested function declarations. Resolving this
seems like another obvious improvement, but one that will potentially require
more significant changes to the structure of `analyze_container` that I wasn't
comfortable trying to make as a first change.
0 commit comments