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 <alice.i.cecile@gmail.com>
This commit is contained in:
Joseph 2024-06-26 06:54:55 -07:00 committed by François
parent e65e4be98c
commit a6feb5ba74
No known key found for this signature in database

View file

@ -827,6 +827,7 @@ pub trait EntityCommand<Marker = ()>: 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<Marker, Self>
where
Self: Sized,