Skip to content

Commit f4920bb

Browse files
committed
Mark TableRow and TableId as repr(transparent) (#7166)
# Objective Following #6681, both `TableRow` and `TableId` are now part of `EntityLocation`. However, the safety invariant on `EntityLocation` requires that all of the constituent fields are `repr(transprent)` or `repr(C)` and the bit pattern of all 1s must be valid. This is not true for `TableRow` and `TableId` currently. ## Solution Mark `TableRow` and `TableId` to satisfy the safety requirement. Add safety comments on `ArchetypeId`, `ArchetypeRow`, `TableId` and `TableRow`.
1 parent dfc4f05 commit f4920bb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

crates/bevy_ecs/src/archetype.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use std::{
4040
/// [`World`]: crate::world::World
4141
/// [`Entities::get`]: crate::entity::Entities
4242
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
43+
// SAFETY: Must be repr(transparent) due to the safety requirements on EntityLocation
4344
#[repr(transparent)]
4445
pub struct ArchetypeRow(u32);
4546

@@ -68,6 +69,7 @@ impl ArchetypeRow {
6869
/// [`World`]: crate::world::World
6970
/// [`EMPTY`]: crate::archetype::ArchetypeId::EMPTY
7071
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
72+
// SAFETY: Must be repr(transparent) due to the safety requirements on EntityLocation
7173
#[repr(transparent)]
7274
pub struct ArchetypeId(u32);
7375

crates/bevy_ecs/src/storage/table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use std::{
2626
/// [`Archetype`]: crate::archetype::Archetype
2727
/// [`Archetype::table_id`]: crate::archetype::Archetype::table_id
2828
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29+
// SAFETY: Must be repr(transparent) due to the safety requirements on EntityLocation
30+
#[repr(transparent)]
2931
pub struct TableId(u32);
3032

3133
impl TableId {
@@ -64,6 +66,8 @@ impl TableId {
6466
/// [`Archetype::table_id`]: crate::archetype::Archetype::table_id
6567
/// [`Entity`]: crate::entity::Entity
6668
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
69+
// SAFETY: Must be repr(transparent) due to the safety requirements on EntityLocation
70+
#[repr(transparent)]
6771
pub struct TableRow(u32);
6872

6973
impl TableRow {

0 commit comments

Comments
 (0)