Skip to content

Conversation

@joriskleiber
Copy link

@joriskleiber joriskleiber commented Aug 17, 2025

This PR is based on the original work in #18118.
Since the author hasn’t been active and I really like this feature, I rebased it onto main and updated it to be working and mergeable again.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 17, 2025
IvarWithoutBones and others added 2 commits August 17, 2025 04:29
This introduces a new assist that adds the derive attributes from a struct or enum to the types of
its fields, recursively. It is recursive in the sense that the fields of field types are also
considered.

The derive attributes will be copied over if the field type meets the following criteria:
* It resides within the same workspace 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.

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
(which already has the derive attribute) implements it, it'll be used to check for manual impls.
This seems to work well in practice.
@joriskleiber joriskleiber force-pushed the recursively-add-derive branch from 4ada227 to a63fc66 Compare August 17, 2025 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants