mirror of
https://github.com/bevyengine/bevy
synced 2024-09-20 14:32:06 +00:00
Mark .id() methods which return an Entity
as must_use (#3750)
# Objective - Calling .id() has no purpose unless you use the Entity returned - This is an easy source of confusion for beginners. - This is easily missed during refactors. ## Solution - Mark the appropriate methods as #[must_use]
This commit is contained in:
parent
f3de12bc5e
commit
f5039a476d
4 changed files with 7 additions and 10 deletions
|
@ -1130,18 +1130,12 @@ mod tests {
|
|||
#[test]
|
||||
fn remove_bundle() {
|
||||
let mut world = World::default();
|
||||
world
|
||||
.spawn()
|
||||
.insert_bundle((A(1), B(1), TableStored("1")))
|
||||
.id();
|
||||
world.spawn().insert_bundle((A(1), B(1), TableStored("1")));
|
||||
let e2 = world
|
||||
.spawn()
|
||||
.insert_bundle((A(2), B(2), TableStored("2")))
|
||||
.id();
|
||||
world
|
||||
.spawn()
|
||||
.insert_bundle((A(3), B(3), TableStored("3")))
|
||||
.id();
|
||||
world.spawn().insert_bundle((A(3), B(3), TableStored("3")));
|
||||
|
||||
let mut query = world.query::<(&B, &TableStored)>();
|
||||
let results = query
|
||||
|
|
|
@ -372,6 +372,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
|
|||
/// # my_system.system();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||
pub fn id(&self) -> Entity {
|
||||
self.entity
|
||||
}
|
||||
|
|
|
@ -493,8 +493,8 @@ mod tests {
|
|||
world.clear_trackers();
|
||||
|
||||
// Then, try removing a component
|
||||
world.spawn().insert(W(3)).id();
|
||||
world.spawn().insert(W(4)).id();
|
||||
world.spawn().insert(W(3));
|
||||
world.spawn().insert(W(4));
|
||||
world.entity_mut(entity_to_remove_w_from).remove::<W<i32>>();
|
||||
|
||||
fn validate_remove(
|
||||
|
|
|
@ -26,6 +26,7 @@ impl<'w> EntityRef<'w> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||
pub fn id(&self) -> Entity {
|
||||
self.entity
|
||||
}
|
||||
|
@ -113,6 +114,7 @@ impl<'w> EntityMut<'w> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||
pub fn id(&self) -> Entity {
|
||||
self.entity
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue