Skip to content

Commit e6d1905

Browse files
committed
a
1 parent c27cc59 commit e6d1905

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

crates/bevy_ecs/src/reflect.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct ReflectComponent {
2323
apply_or_insert: fn(&mut World, Entity, &dyn Reflect),
2424
remove: fn(&mut World, Entity),
2525
reflect: fn(&World, Entity) -> Option<&dyn Reflect>,
26-
reflect_mut: unsafe fn(&World, Entity) -> Option<ReflectMut>,
26+
reflect_mut: fn(&mut World, Entity) -> Option<ReflectMut>,
2727
copy: fn(&World, &mut World, Entity, Entity),
2828
}
2929

@@ -71,21 +71,6 @@ impl ReflectComponent {
7171

7272
/// Gets the value of this [`Component`] type from the entity as a mutable reflected reference.
7373
pub fn reflect_mut<'a>(&self, world: &'a mut World, entity: Entity) -> Option<ReflectMut<'a>> {
74-
// SAFETY: unique world access
75-
unsafe { (self.reflect_mut)(world, entity) }
76-
}
77-
78-
/// # Safety
79-
/// This method does not prevent you from having two mutable pointers to the same data,
80-
/// violating Rust's aliasing rules. To avoid this:
81-
/// * Only call this method in an exclusive system to avoid sharing across threads (or use a
82-
/// scheduler that enforces safe memory access).
83-
/// * Don't call this method more than once in the same scope for a given [`Component`].
84-
pub unsafe fn reflect_unchecked_mut<'a>(
85-
&self,
86-
world: &'a World,
87-
entity: Entity,
88-
) -> Option<ReflectMut<'a>> {
8974
(self.reflect_mut)(world, entity)
9075
}
9176

@@ -149,17 +134,10 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
149134
.map(|c| c as &dyn Reflect)
150135
},
151136
reflect_mut: |world, entity| {
152-
// SAFETY: reflect_mut is an unsafe function pointer used by `reflect_unchecked_mut` which promises to never
153-
// produce aliasing mutable references, and reflect_mut, which has mutable world access
154-
unsafe {
155-
world
156-
.get_entity(entity)?
157-
.get_unchecked_mut::<C>(world.last_change_tick(), world.read_change_tick())
158-
.map(|c| ReflectMut {
159-
value: c.value as &mut dyn Reflect,
160-
ticks: c.ticks,
161-
})
162-
}
137+
world.get_mut::<C>(entity).map(|c| ReflectMut {
138+
value: c.value as &mut dyn Reflect,
139+
ticks: c.ticks,
140+
})
163141
},
164142
}
165143
}

crates/bevy_ecs/src/system/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
10741074
.has_write(archetype_component)
10751075
{
10761076
entity_ref
1077-
.get_unchecked_mut::<T>(self.last_change_tick, self.change_tick)
1077+
.__get_unchecked_mut::<T>(self.last_change_tick, self.change_tick)
10781078
.ok_or(QueryComponentError::MissingComponent)
10791079
} else {
10801080
Err(QueryComponentError::MissingWriteAccess)

crates/bevy_ecs/src/world/entity_ref.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ impl<'w> EntityRef<'w> {
8383
}
8484
}
8585

86+
/// Do not use this. It will be removed eventually and only exists for `Query::get_component_unchecked_mut`.
87+
///
8688
/// Gets a mutable reference to the component of type `T` associated with
8789
/// this entity without ensuring there are no other borrows active and without
8890
/// ensuring that the returned reference will stay valid.
@@ -94,7 +96,7 @@ impl<'w> EntityRef<'w> {
9496
/// may happen from **any** `insert_component`, `remove_component` or `despawn`
9597
/// operation on this world (non-exhaustive list).
9698
#[inline]
97-
pub unsafe fn get_unchecked_mut<T: Component>(
99+
pub(crate) unsafe fn __get_unchecked_mut<T: Component>(
98100
&self,
99101
last_change_tick: u32,
100102
change_tick: u32,

0 commit comments

Comments
 (0)