Skip to content

Commit 947474f

Browse files
committed
nits
1 parent 8e8ecc4 commit 947474f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

crates/bevy_ecs/src/world/unsafe_world_cell.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ impl<'w> UnsafeWorldCell<'w> {
8787
pub(crate) fn new_mutable(world: &'w mut World) -> Self {
8888
// SAFETY: raw pointer is derived from an `&mut World` and `Unsafecell<World>` has
8989
// the same layout as `World`.
90-
unsafe {
91-
let world: &'w UnsafeCell<World> = &*(world as *mut World as *mut UnsafeCell<World>);
92-
Self(world as *const UnsafeCell<World> as *mut World, PhantomData)
93-
}
90+
unsafe { Self(world as *mut World, PhantomData) }
9491
}
9592

9693
/// This `&mut World` counts as a mutable borrow of every resource and component for the purposes
9794
/// of safety invariants that talk about borrows on component/resource data not existing. This is
9895
/// true even for methods that do not explicitly call out `&mut World` as problematic.
9996
///
10097
/// # Safety
98+
/// - must have permission to access everything mutably
10199
/// - there must be no borrows on world
102100
pub unsafe fn world_mut(self) -> &'w mut World {
103101
// SAFETY:
@@ -109,6 +107,7 @@ impl<'w> UnsafeWorldCell<'w> {
109107
/// This can be used for arbitrary shared/readonly access.
110108
///
111109
/// # Safety
110+
/// - must have permission to access the whole world immutably
112111
/// - there must be no live exclusive borrows on world data
113112
/// - there must be no live exclusive borrow of world
114113
pub unsafe fn world(self) -> &'w World {
@@ -129,7 +128,7 @@ impl<'w> UnsafeWorldCell<'w> {
129128
///
130129
/// # Safety
131130
/// - there must be no live exclusive borrow of the world
132-
/// - must not be used in a way that would conflcit with any
131+
/// - must not be used in a way that would conflict with any
133132
/// live exclusive borrows on world data
134133
unsafe fn unsafe_world(self) -> &'w World {
135134
// SAFETY:

crates/bevy_ecs/src/world/world_cell.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'w> WorldCell<'w> {
200200
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
201201
let component_id = unsafe { self.world.components() }.get_resource_id(TypeId::of::<T>())?;
202202

203-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
203+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
204204
let archetype_component_id = unsafe {
205205
self.world
206206
.get_resource_archetype_component_id(component_id)?
@@ -235,10 +235,10 @@ impl<'w> WorldCell<'w> {
235235

236236
/// Gets a mutable reference to the resource of the given type
237237
pub fn get_resource_mut<T: Resource>(&self) -> Option<WorldBorrowMut<'_, T>> {
238-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
238+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
239239
let component_id = unsafe { self.world.components() }.get_resource_id(TypeId::of::<T>())?;
240240

241-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
241+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
242242
let archetype_component_id = unsafe {
243243
self.world
244244
.get_resource_archetype_component_id(component_id)?
@@ -272,10 +272,10 @@ impl<'w> WorldCell<'w> {
272272

273273
/// Gets an immutable reference to the non-send resource of the given type, if it exists.
274274
pub fn get_non_send_resource<T: 'static>(&self) -> Option<WorldBorrow<'_, T>> {
275-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
275+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
276276
let component_id = unsafe { self.world.components() }.get_resource_id(TypeId::of::<T>())?;
277277

278-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
278+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
279279
let archetype_component_id = unsafe {
280280
self.world
281281
.get_non_send_archetype_component_id(component_id)?
@@ -309,10 +309,10 @@ impl<'w> WorldCell<'w> {
309309

310310
/// Gets a mutable reference to the non-send resource of the given type, if it exists.
311311
pub fn get_non_send_resource_mut<T: 'static>(&self) -> Option<WorldBorrowMut<'_, T>> {
312-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
312+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
313313
let component_id = unsafe { self.world.components() }.get_resource_id(TypeId::of::<T>())?;
314314

315-
// SAFETY: `WorldCell` onyl makes a `&mut World` on drop so its fine to access metadata here
315+
// SAFETY: `WorldCell` only makes a `&mut World` on drop so its fine to access metadata here
316316
let archetype_component_id = unsafe {
317317
self.world
318318
.get_non_send_archetype_component_id(component_id)?

0 commit comments

Comments
 (0)