Skip to content

Commit

Permalink
clean up safety comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Nov 4, 2022
1 parent 6ed25de commit 9daeae7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'w> EntityRef<'w> {
///
/// # Safety
///
/// - The returned reference must never alias a mutable borrow of this component.
/// - The returned reference must never alias another reference to 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).
Expand All @@ -149,7 +149,8 @@ impl<'w> EntityRef<'w> {
component_id: ComponentId,
) -> Option<MutUntyped<'w>> {
self.world.components().get_info(component_id)?;
// SAFETY: entity_location is valid, component_id is valid as checked by the line above, world access is promised by the caller
// SAFETY: entity_location is valid, component_id is valid as checked by the line above,
// the caller promises that they can uniquely access this component
get_mut_by_id(self.world, self.entity, self.location, component_id)
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,14 +1480,16 @@ impl World {
let ticks = Ticks {
// SAFETY:
// - index is in-bounds because the column is initialized and non-empty
// - no other reference to the ticks of the same row can exist at the same time
// - the caller of this function has to ensure that they can mutably access this
// component for the duration of the `'_` lifetime. This includes access to the `ComponentTicks`
component_ticks: ticks.deref_mut(),
last_change_tick: self.last_change_tick(),
change_tick: self.read_change_tick(),
};

Some(MutUntyped {
// SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
// SAFETY: the caller of this function has to ensure that they can mutably access this
// component for the duration of the `'_` lifetime
value: ptr.assert_unique(),
ticks,
})
Expand Down

0 comments on commit 9daeae7

Please sign in to comment.