Skip to content

Commit

Permalink
remove 'unused' unsafe blocks until rust-lang/rust#100081 lands
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Sep 9, 2022
1 parent e0a6c71 commit d723291
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'w> EntityRef<'w> {
) -> 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
unsafe { get_mut_by_id(self.world, self.entity, self.location, component_id) }
get_mut_by_id(self.world, self.entity, self.location, component_id)
}
}

Expand Down
9 changes: 4 additions & 5 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,20 +1427,19 @@ impl World {

let column = self.get_populated_resource_column(component_id)?;

// SAFETY: get_data_ptr requires that the mutability rules are not violated, and the caller promises
// to only modify the resource while the mutable borrow of the world is valid
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
component_ticks: unsafe { &mut *column.get_ticks_unchecked(0).get() },
component_ticks: &mut *column.get_ticks_unchecked(0).get(),
last_change_tick: self.last_change_tick(),
change_tick: self.read_change_tick(),
};

Some(MutUntyped {
// SAFETY: world access is unique, so no other reference can exist at the same time
value: unsafe { column.get_data_ptr().assert_unique() },
// SAFETY: get_data_ptr requires that the mutability rules are not violated, and the caller promises
// to only modify the resource while the mutable borrow of the world is valid
value: column.get_data_ptr().assert_unique(),
ticks,
})
}
Expand Down

0 comments on commit d723291

Please sign in to comment.