Skip to content

Commit a6feb5b

Browse files
joseph-gioalice-i-cecile
authored andcommitted
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 <[email protected]>
1 parent e65e4be commit a6feb5b

File tree

1 file changed

+1
-0
lines changed
  • crates/bevy_ecs/src/system/commands

1 file changed

+1
-0
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ pub trait EntityCommand<Marker = ()>: Send + 'static {
827827
/// Executes this command for the given [`Entity`].
828828
fn apply(self, id: Entity, world: &mut World);
829829
/// Returns a [`Command`] which executes this [`EntityCommand`] for the given [`Entity`].
830+
#[must_use = "commands do nothing unless applied to a `World`"]
830831
fn with_entity(self, id: Entity) -> WithEntity<Marker, Self>
831832
where
832833
Self: Sized,

0 commit comments

Comments
 (0)