diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index ba766c5fbd..473b8c3b80 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -72,6 +72,12 @@ pub struct Commands<'w, 's> { entities: &'w Entities, } +// SAFETY: All commands [`Command`] implement [`Send`] +unsafe impl Send for Commands<'_, '_> {} + +// SAFETY: `Commands` never gives access to the inner commands. +unsafe impl Sync for Commands<'_, '_> {} + const _: () = { type __StructFieldsAlias<'w, 's> = (Deferred<'s, CommandQueue>, &'w Entities); #[doc(hidden)] @@ -1556,6 +1562,15 @@ mod tests { assert!(world.contains_resource::>()); } + fn is_send() {} + fn is_sync() {} + + #[test] + fn test_commands_are_send_and_sync() { + is_send::(); + is_sync::(); + } + #[test] fn append() { let mut world = World::default();