Fix relationship macro for multiple named members fields (#18530)
# Objective Fixes #18466 ## Solution Updated the macro generation pattern to place the comma in the correct place in the pattern. ## Testing - Tried named and unnamed fields in combination, and used rust expand macro tooling to see the generated code and verify its correctness (see screenshots in example below) --- ## Showcase Screenshot showing expanded macro with multiple named fields  Screenshot showing expanded macro with single unnamed field  ## Migration Guide n/a
This commit is contained in:
parent
a7e6578733
commit
83ffc90c6c
@ -746,7 +746,7 @@ fn derive_relationship(
|
||||
#[inline]
|
||||
fn from(entity: #bevy_ecs_path::entity::Entity) -> Self {
|
||||
Self {
|
||||
#(#members: core::default::Default::default(),),*
|
||||
#(#members: core::default::Default::default(),)*
|
||||
#relationship_member: entity
|
||||
}
|
||||
}
|
||||
@ -809,7 +809,7 @@ fn derive_relationship_target(
|
||||
#[inline]
|
||||
fn from_collection_risky(collection: Self::Collection) -> Self {
|
||||
Self {
|
||||
#(#members: core::default::Default::default(),),*
|
||||
#(#members: core::default::Default::default(),)*
|
||||
#relationship_member: collection
|
||||
}
|
||||
}
|
||||
|
@ -385,4 +385,41 @@ mod tests {
|
||||
assert!(!world.entity(b).contains::<Rel>());
|
||||
assert!(!world.entity(b).contains::<RelTarget>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relationship_with_multiple_non_target_fields_compiles() {
|
||||
#[derive(Component)]
|
||||
#[relationship(relationship_target=Target)]
|
||||
#[expect(dead_code, reason = "test struct")]
|
||||
struct Source {
|
||||
#[relationship]
|
||||
target: Entity,
|
||||
foo: u8,
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
#[relationship_target(relationship=Source)]
|
||||
struct Target(Vec<Entity>);
|
||||
|
||||
// No assert necessary, looking to make sure compilation works with the macros
|
||||
}
|
||||
#[test]
|
||||
fn relationship_target_with_multiple_non_target_fields_compiles() {
|
||||
#[derive(Component)]
|
||||
#[relationship(relationship_target=Target)]
|
||||
struct Source(Entity);
|
||||
|
||||
#[derive(Component)]
|
||||
#[relationship_target(relationship=Source)]
|
||||
#[expect(dead_code, reason = "test struct")]
|
||||
struct Target {
|
||||
#[relationship]
|
||||
target: Vec<Entity>,
|
||||
foo: u8,
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
// No assert necessary, looking to make sure compilation works with the macros
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user