From 36a2f7fdf13219ffe0b0a46c5f184a02173e2c6f Mon Sep 17 00:00:00 2001 From: JaySpruce Date: Tue, 25 Feb 2025 17:34:46 -0600 Subject: [PATCH] Remove unnecessary bounds on `EntityClonerBuilder::without_required_components` (#17969) ## Objective The closure argument for `EntityClonerBuilder::without_required_components` has `Send + Sync + 'static` bounds, but the closure immediately gets called and never needs to be sent anywhere. (This was my fault :P ) ## Solution Remove the bounds so that users aren't unnecessarily restricted. I also took the opportunity to expand the tests a little. --- crates/bevy_ecs/src/entity/clone_entities.rs | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index 389f30ff8d..9b8a36ac6d 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -609,7 +609,7 @@ impl<'w> EntityClonerBuilder<'w> { /// will not involve required components. pub fn without_required_components( &mut self, - builder: impl FnOnce(&mut EntityClonerBuilder) + Send + Sync + 'static, + builder: impl FnOnce(&mut EntityClonerBuilder), ) -> &mut Self { self.attach_required_components = false; builder(self); @@ -1189,9 +1189,7 @@ mod tests { EntityCloner::build(&mut world) .deny_all() - .without_required_components(|builder| { - builder.allow::(); - }) + .allow::() .clone_entity(e, e_clone); assert_eq!(world.entity(e_clone).get::(), None); @@ -1199,6 +1197,36 @@ mod tests { assert_eq!(world.entity(e_clone).get::(), Some(&C(5))); } + #[test] + fn clone_entity_with_default_required_components() { + #[derive(Component, Clone, PartialEq, Debug)] + #[require(B)] + struct A; + + #[derive(Component, Clone, PartialEq, Debug, Default)] + #[require(C(|| C(5)))] + struct B; + + #[derive(Component, Clone, PartialEq, Debug)] + struct C(u32); + + let mut world = World::default(); + + let e = world.spawn((A, C(0))).id(); + let e_clone = world.spawn_empty().id(); + + EntityCloner::build(&mut world) + .deny_all() + .without_required_components(|builder| { + builder.allow::(); + }) + .clone_entity(e, e_clone); + + assert_eq!(world.entity(e_clone).get::(), Some(&A)); + assert_eq!(world.entity(e_clone).get::(), Some(&B)); + assert_eq!(world.entity(e_clone).get::(), Some(&C(5))); + } + #[test] fn clone_entity_with_dynamic_components() { const COMPONENT_SIZE: usize = 10;