From a6feb5ba7469708ca7a913ae604016ef6c340907 Mon Sep 17 00:00:00 2001 From: Joseph <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 26 Jun 2024 06:54:55 -0700 Subject: [PATCH] Emit a warning if the result of `EntityCommand::with_entity` is not used (#14028) When using combinators such as `EntityCommand::with_entity` to build commands, it can be easy to forget to apply that command, leading to dead code. In many cases this doesn't even lead to an unused variable warning, which can make these mistakes difficult to track down Annotate the method with `#[must_use]` Co-authored-by: Alice Cecile --- crates/bevy_ecs/src/system/commands/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 028182e69f..0db820a374 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -827,6 +827,7 @@ pub trait EntityCommand: Send + 'static { /// Executes this command for the given [`Entity`]. fn apply(self, id: Entity, world: &mut World); /// Returns a [`Command`] which executes this [`EntityCommand`] for the given [`Entity`]. + #[must_use = "commands do nothing unless applied to a `World`"] fn with_entity(self, id: Entity) -> WithEntity where Self: Sized,