From 2b7d54b3004c8bbedd116bf5e7ade349b8220ef0 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) # Objective 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 ## Solution 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 d8d2914187..d752d80808 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -832,6 +832,7 @@ pub trait EntityCommand: Send + 'static { /// You can override the provided implementation if you can return a `Command` with a smaller memory /// footprint than `(Entity, Self)`. /// In most cases the provided implementation is sufficient. + #[must_use = "commands do nothing unless applied to a `World`"] fn with_entity(self, entity: Entity) -> impl Command where Self: Sized,