feature: add the "Recursively add derive" assist
This introduces a new assist that adds the derive attributes from a struct or enum to the types of its fields, recursively:
The derive attributes will be copied over if the field type meets the following criteria:
- It resides within the same crate as the "top-level" type, to avoid editing the crate registry.
- It does not already have the same derive attribute.
- It does not have a manual implementation of the trait likely implemented by the derive.
The last criteria is a bit of a guess since it isn't possible to know what trait implementation(s) a derive macro generates. If a trait has the same name as the derive macro and the top-level type (from which we're copying the derive attribute) implements it, it'll be used to check for manual impls. This seems to work well in practice :)
Fixes #12330
Thanks for the reviews, I've fixed most comments. Supporting non-ADTs and using SyntaxEditor will take a bit more investigation so I'll push that once it's ready.
@bors delegate=ChayimFriedman2
:v: @ChayimFriedman2, you can now approve this pull request!
If @Veykril told you to "r=me" after making some further change, please make that change, then do @bors r=@Veykril
:umbrella: The latest upstream changes (presumably #18415) made this pull request unmergeable. Please resolve the merge conflicts.
Hello @IvarWithoutBones, would you happen to have time to finish this PR? We're planning to deprecate some of the SyntaxEditor APIs soon, so it would be ideal if this could be merged before that. If you're busy, would it be okay if I added a few more commits to your current work and completed the PR myself?
Hi @IvarWithoutBones, do you still want to pursue this PR?
If not, we'll merge the derivative work of @joriskleiber (https://github.com/rust-lang/rust-analyzer/pull/20474).