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 <alice.i.cecile@gmail.com>
This commit is contained in:
Joseph 2024-06-26 06:54:55 -07:00 committed by GitHub
parent ee63cf45c6
commit 2b7d54b300
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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