Skip to content

Commit 0385ed6

Browse files
Remove MaybeUninit
1 parent 05bf567 commit 0385ed6

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

crates/bevy_ecs/src/change_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ impl MaybeLocation {
15171517
/// within a non-tracked function body.
15181518
#[inline]
15191519
#[track_caller]
1520-
pub fn caller() -> Self {
1520+
pub const fn caller() -> Self {
15211521
// Note that this cannot use `new_with`, since `FnOnce` invocations cannot be annotated with `#[track_caller]`.
15221522
MaybeLocation {
15231523
#[cfg(feature = "track_location")]

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ use crate::{
8181
};
8282
use alloc::vec::Vec;
8383
use bevy_platform::sync::atomic::Ordering;
84-
use core::{
85-
fmt,
86-
hash::Hash,
87-
mem::{self, MaybeUninit},
88-
num::NonZero,
89-
panic::Location,
90-
};
84+
use core::{fmt, hash::Hash, mem, num::NonZero, panic::Location};
9185
use log::warn;
9286

9387
#[cfg(feature = "serialize")]
@@ -928,7 +922,7 @@ impl Entities {
928922
pub(crate) unsafe fn mark_spawn_despawn(&mut self, index: u32, by: MaybeLocation, at: Tick) {
929923
// SAFETY: Caller guarantees that `index` a valid entity index
930924
let meta = unsafe { self.meta.get_unchecked_mut(index as usize) };
931-
meta.spawned_or_despawned = MaybeUninit::new(SpawnedOrDespawned { by, at });
925+
meta.spawned_or_despawned = SpawnedOrDespawned { by, at };
932926
}
933927

934928
/// Increments the `generation` of a freed [`Entity`]. The next entity ID allocated with this
@@ -1006,7 +1000,7 @@ impl Entities {
10061000
Entity::from_raw_and_generation(row, meta.generation),
10071001
&mut meta.location,
10081002
);
1009-
meta.spawned_or_despawned = MaybeUninit::new(SpawnedOrDespawned { by, at });
1003+
meta.spawned_or_despawned = SpawnedOrDespawned { by, at };
10101004
}
10111005

10121006
*free_cursor = 0;
@@ -1019,7 +1013,7 @@ impl Entities {
10191013
Entity::from_raw_and_generation(row, meta.generation),
10201014
&mut meta.location,
10211015
);
1022-
meta.spawned_or_despawned = MaybeUninit::new(SpawnedOrDespawned { by, at });
1016+
meta.spawned_or_despawned = SpawnedOrDespawned { by, at };
10231017
}
10241018
}
10251019

@@ -1121,10 +1115,7 @@ impl Entities {
11211115
(meta.generation == entity.generation)
11221116
|| (meta.location.archetype_id == ArchetypeId::INVALID)
11231117
&& (meta.generation == entity.generation.after_versions(1)))
1124-
.map(|meta| {
1125-
// SAFETY: valid archetype or non-min generation is proof this is init
1126-
unsafe { meta.spawned_or_despawned.assume_init() }
1127-
})
1118+
.map(|meta| meta.spawned_or_despawned)
11281119
}
11291120

11301121
/// Returns the source code location from which this entity has last been spawned
@@ -1141,9 +1132,7 @@ impl Entities {
11411132
) -> (MaybeLocation, Tick) {
11421133
// SAFETY: caller ensures entity is allocated
11431134
let meta = unsafe { self.meta.get_unchecked(entity.index() as usize) };
1144-
// SAFETY: caller ensures entities of this index were at least spawned
1145-
let spawned_or_despawned = unsafe { meta.spawned_or_despawned.assume_init() };
1146-
(spawned_or_despawned.by, spawned_or_despawned.at)
1135+
(meta.spawned_or_despawned.by, meta.spawned_or_despawned.at)
11471136
}
11481137

11491138
#[inline]
@@ -1152,9 +1141,7 @@ impl Entities {
11521141
if meta.generation != EntityGeneration::FIRST
11531142
|| meta.location.archetype_id != ArchetypeId::INVALID
11541143
{
1155-
// SAFETY: non-min generation or valid archetype is proof this is init
1156-
let spawned_or_despawned = unsafe { meta.spawned_or_despawned.assume_init_mut() };
1157-
spawned_or_despawned.at.check_tick(change_tick);
1144+
meta.spawned_or_despawned.at.check_tick(change_tick);
11581145
}
11591146
}
11601147
}
@@ -1219,7 +1206,7 @@ struct EntityMeta {
12191206
/// The current location of the [`EntityRow`].
12201207
pub location: EntityLocation,
12211208
/// Location of the last spawn, despawn or flush of this entity.
1222-
spawned_or_despawned: MaybeUninit<SpawnedOrDespawned>,
1209+
spawned_or_despawned: SpawnedOrDespawned,
12231210
}
12241211

12251212
#[derive(Copy, Clone, Debug)]
@@ -1233,7 +1220,10 @@ impl EntityMeta {
12331220
const EMPTY: EntityMeta = EntityMeta {
12341221
generation: EntityGeneration::FIRST,
12351222
location: EntityLocation::INVALID,
1236-
spawned_or_despawned: MaybeUninit::uninit(),
1223+
spawned_or_despawned: SpawnedOrDespawned {
1224+
by: MaybeLocation::caller(),
1225+
at: Tick::new(0),
1226+
},
12371227
};
12381228
}
12391229

0 commit comments

Comments
 (0)