@@ -855,15 +855,18 @@ fn sorted_remove<T: Eq + Ord + Copy>(source: &mut Vec<T>, remove: &[T]) {
855
855
856
856
// SAFETY: EntityLocation must be valid
857
857
#[ inline]
858
- pub ( crate ) unsafe fn get_mut < T : Component > (
859
- world : & mut World ,
858
+ pub ( crate ) unsafe fn get_mut < ' w , T : Component > (
859
+ world : & ' w mut World ,
860
860
entity : Entity ,
861
861
location : EntityLocation ,
862
862
) -> Option < Mut < ' _ , T > > {
863
- // SAFETY: world access is unique, entity location is valid, and returned component is of type
864
- // T, storage type is correct
865
863
let change_tick = world. change_tick ( ) ;
866
864
let last_change_tick = world. last_change_tick ( ) ;
865
+ // SAFETY:
866
+ // - world access is unique
867
+ // - entity location is valid
868
+ // - and returned component is of type T
869
+ // - archetypes and components comes from the same world
867
870
world
868
871
. storages
869
872
. get_component_and_ticks_with_type (
@@ -875,6 +878,9 @@ pub(crate) unsafe fn get_mut<T: Component>(
875
878
location,
876
879
)
877
880
. map ( |( value, ticks) | Mut {
881
+ // SAFETY:
882
+ // - world access is unique and ties world lifetime to `Mut` lifetime
883
+ // - `value` is of type `T`
878
884
value : value. assert_unique ( ) . deref_mut :: < T > ( ) ,
879
885
ticks : TicksMut :: from_tick_cells ( ticks, last_change_tick, change_tick) ,
880
886
} )
@@ -887,10 +893,15 @@ pub(crate) unsafe fn get_mut_by_id(
887
893
entity : Entity ,
888
894
location : EntityLocation ,
889
895
component_id : ComponentId ,
890
- ) -> Option < MutUntyped > {
896
+ ) -> Option < MutUntyped < ' _ > > {
891
897
let change_tick = world. change_tick ( ) ;
898
+ // SAFETY: component_id is valid
892
899
let info = world. components . get_info_unchecked ( component_id) ;
893
- // SAFETY: world access is unique, entity location and component_id required to be valid, storage_type is correct
900
+ // SAFETY:
901
+ // - world access is unique
902
+ // - entity location is valid
903
+ // - and returned component is of type T
904
+ // - archetypes and components comes from the same world
894
905
world
895
906
. storages
896
907
. get_component_and_ticks (
@@ -901,6 +912,7 @@ pub(crate) unsafe fn get_mut_by_id(
901
912
location,
902
913
)
903
914
. map ( |( value, ticks) | MutUntyped {
915
+ // SAFETY: world access is unique and ties world lifetime to `MutUntyped` lifetime
904
916
value : value. assert_unique ( ) ,
905
917
ticks : TicksMut :: from_tick_cells ( ticks, world. last_change_tick ( ) , change_tick) ,
906
918
} )
0 commit comments