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
@ -1130,18 +1130,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn remove_bundle() {
|
fn remove_bundle() {
|
||||||
let mut world = World::default();
|
let mut world = World::default();
|
||||||
world
|
world.spawn().insert_bundle((A(1), B(1), TableStored("1")));
|
||||||
.spawn()
|
|
||||||
.insert_bundle((A(1), B(1), TableStored("1")))
|
|
||||||
.id();
|
|
||||||
let e2 = world
|
let e2 = world
|
||||||
.spawn()
|
.spawn()
|
||||||
.insert_bundle((A(2), B(2), TableStored("2")))
|
.insert_bundle((A(2), B(2), TableStored("2")))
|
||||||
.id();
|
.id();
|
||||||
world
|
world.spawn().insert_bundle((A(3), B(3), TableStored("3")));
|
||||||
.spawn()
|
|
||||||
.insert_bundle((A(3), B(3), TableStored("3")))
|
|
||||||
.id();
|
|
||||||
|
|
||||||
let mut query = world.query::<(&B, &TableStored)>();
|
let mut query = world.query::<(&B, &TableStored)>();
|
||||||
let results = query
|
let results = query
|
||||||
|
|||||||
@ -372,6 +372,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
|
|||||||
/// # my_system.system();
|
/// # my_system.system();
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||||
pub fn id(&self) -> Entity {
|
pub fn id(&self) -> Entity {
|
||||||
self.entity
|
self.entity
|
||||||
}
|
}
|
||||||
|
|||||||
@ -493,8 +493,8 @@ mod tests {
|
|||||||
world.clear_trackers();
|
world.clear_trackers();
|
||||||
|
|
||||||
// Then, try removing a component
|
// Then, try removing a component
|
||||||
world.spawn().insert(W(3)).id();
|
world.spawn().insert(W(3));
|
||||||
world.spawn().insert(W(4)).id();
|
world.spawn().insert(W(4));
|
||||||
world.entity_mut(entity_to_remove_w_from).remove::<W<i32>>();
|
world.entity_mut(entity_to_remove_w_from).remove::<W<i32>>();
|
||||||
|
|
||||||
fn validate_remove(
|
fn validate_remove(
|
||||||
|
|||||||
@ -26,6 +26,7 @@ impl<'w> EntityRef<'w> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||||
pub fn id(&self) -> Entity {
|
pub fn id(&self) -> Entity {
|
||||||
self.entity
|
self.entity
|
||||||
}
|
}
|
||||||
@ -113,6 +114,7 @@ impl<'w> EntityMut<'w> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use = "Omit the .id() call if you do not need to store the `Entity` identifier."]
|
||||||
pub fn id(&self) -> Entity {
|
pub fn id(&self) -> Entity {
|
||||||
self.entity
|
self.entity
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user