From 0fdb45ce90ffa75dabf9208b3f6158ad3950b429 Mon Sep 17 00:00:00 2001 From: TheRawMeatball Date: Fri, 22 Apr 2022 20:06:41 +0000 Subject: [PATCH] Remove EntityMut::get_unchecked (#4547) The only way to soundly use this API is already encapsulated within `EntityMut::get`, so this api is removed. # Migration guide Replace calls to `EntityMut::get_unchecked` with calls to `EntityMut::get`. --- crates/bevy_ecs/src/world/entity_ref.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 5a18b3ad34ebb..6946cb1378a89 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -154,7 +154,10 @@ impl<'w> EntityMut<'w> { #[inline] pub fn get(&self) -> Option<&'_ T> { // SAFE: lifetimes enforce correct usage of returned borrow - unsafe { self.get_unchecked::() } + unsafe { + get_component_with_type(self.world, TypeId::of::(), self.entity, self.location) + .map(|value| &*value.cast::()) + } } #[inline] @@ -163,23 +166,6 @@ impl<'w> EntityMut<'w> { unsafe { self.get_unchecked_mut::() } } - /// Gets an immutable reference to the component of type `T` associated with - /// this entity without ensuring there are no unique borrows active and without - /// ensuring that the returned reference will stay valid. - /// - /// # Safety - /// - /// - The returned reference must never alias a mutable borrow of this component. - /// - The returned reference must not be used after this component is moved which - /// may happen from **any** `insert_component`, `remove_component` or `despawn` - /// operation on this world (non-exhaustive list). - #[inline] - pub unsafe fn get_unchecked(&self) -> Option<&'w T> { - // SAFE: entity location is valid and returned component is of type T - get_component_with_type(self.world, TypeId::of::(), self.entity, self.location) - .map(|value| &*value.cast::()) - } - /// Gets a mutable reference to the component of type `T` associated with /// this entity without ensuring there are no other borrows active and without /// ensuring that the returned reference will stay valid.