Refactor bundle derive#19749
Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom Jun 20, 2025
Merged
Conversation
alice-i-cecile
approved these changes
Jun 20, 2025
ElliottjPierce
approved these changes
Jun 20, 2025
Contributor
ElliottjPierce
left a comment
There was a problem hiding this comment.
Looks good to me! Much cleaner now IMO
Trashtalk217
pushed a commit
to Trashtalk217/bevy
that referenced
this pull request
Jul 10, 2025
# Objective - Splitted off from bevyengine#19491 - Make adding generated code to the `Bundle` derive macro easier - Fix a bug when multiple fields are `#[bundle(ignore)]` ## Solution - Instead of accumulating the code for each method in a different `Vec`, accumulate only the names of non-ignored fields and their types, then use `quote` to generate the code for each of them in the method body. - To fix the bug, change the code populating the `BundleFieldKind` to push only one of them per-field (previously each `#[bundle(ignore)]` resulted in pushing twice, once for the correct `BundleFieldKind::Ignore` and then again unconditionally for `BundleFieldKind::Component`) ## Testing - Added a regression test for the bug that was fixed
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.
Objective
Optionbundles andBox<dyn Bundle>#19491Bundlederive macro easier#[bundle(ignore)]Solution
Vec, accumulate only the names of non-ignored fields and their types, then usequoteto generate the code for each of them in the method body.BundleFieldKindto push only one of them per-field (previously each#[bundle(ignore)]resulted in pushing twice, once for the correctBundleFieldKind::Ignoreand then again unconditionally forBundleFieldKind::Component)Testing