Skip to content

Commit 9daeae7

Browse files
clean up safety comments
1 parent 6ed25de commit 9daeae7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/bevy_ecs/src/world/entity_ref.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'w> EntityRef<'w> {
139139
///
140140
/// # Safety
141141
///
142-
/// - The returned reference must never alias a mutable borrow of this component.
142+
/// - The returned reference must never alias another reference to this component
143143
/// - The returned reference must not be used after this component is moved which
144144
/// may happen from **any** `insert_component`, `remove_component` or `despawn`
145145
/// operation on this world (non-exhaustive list).
@@ -149,7 +149,8 @@ impl<'w> EntityRef<'w> {
149149
component_id: ComponentId,
150150
) -> Option<MutUntyped<'w>> {
151151
self.world.components().get_info(component_id)?;
152-
// SAFETY: entity_location is valid, component_id is valid as checked by the line above, world access is promised by the caller
152+
// SAFETY: entity_location is valid, component_id is valid as checked by the line above,
153+
// the caller promises that they can uniquely access this component
153154
get_mut_by_id(self.world, self.entity, self.location, component_id)
154155
}
155156
}

crates/bevy_ecs/src/world/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,14 +1480,16 @@ impl World {
14801480
let ticks = Ticks {
14811481
// SAFETY:
14821482
// - index is in-bounds because the column is initialized and non-empty
1483-
// - no other reference to the ticks of the same row can exist at the same time
1483+
// - the caller of this function has to ensure that they can mutably access this
1484+
// component for the duration of the `'_` lifetime. This includes access to the `ComponentTicks`
14841485
component_ticks: ticks.deref_mut(),
14851486
last_change_tick: self.last_change_tick(),
14861487
change_tick: self.read_change_tick(),
14871488
};
14881489

14891490
Some(MutUntyped {
1490-
// SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
1491+
// SAFETY: the caller of this function has to ensure that they can mutably access this
1492+
// component for the duration of the `'_` lifetime
14911493
value: ptr.assert_unique(),
14921494
ticks,
14931495
})

0 commit comments

Comments
 (0)