Skip to content

Commit 63b16a8

Browse files
committed
Removing some unnecessary unsafe and adding Miri to workflow
1 parent 6c2c37e commit 63b16a8

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

.github/workflows/rust.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ jobs:
2626
run: cargo test --verbose --features="sync"
2727
- name: Run tests with all features
2828
run: cargo test --verbose --all-features
29+
- name: Run Miri
30+
run: |
31+
rustup toolchain install nightly --component miri
32+
cargo +nightly miri test --all-features

src/entity.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt::Display;
22
use std::fmt::{Debug, Formatter, Result as FmtResult};
33
use std::hash::{Hash, Hasher};
44
use std::marker::PhantomData;
5-
use std::mem;
65
use std::num::NonZeroU32;
76

87
use crate::error::EcsError;
@@ -539,44 +538,28 @@ where
539538
impl<'a, A: Archetype> From<&'a Entity<A>> for &'a EntityAny {
540539
#[inline(always)]
541540
fn from(value: &'a Entity<A>) -> Self {
542-
unsafe {
543-
// SAFETY: Entity<A> is a transparent struct containing only an EntityAny,
544-
// which guarantees that they have the same representation in memory
545-
mem::transmute(value)
546-
}
541+
&value.inner
547542
}
548543
}
549544

550545
impl<'a, A: Archetype> From<&'a EntityDirect<A>> for &'a EntityDirectAny {
551546
#[inline(always)]
552547
fn from(value: &'a EntityDirect<A>) -> Self {
553-
unsafe {
554-
// SAFETY: EntityDirect<A> is a transparent struct containing only an EntityDirectAny,
555-
// which guarantees that they have the same representation in memory
556-
mem::transmute(value)
557-
}
548+
&value.inner
558549
}
559550
}
560551

561552
impl<'a, A: Archetype> From<&'a mut Entity<A>> for &'a mut EntityAny {
562553
#[inline(always)]
563554
fn from(value: &'a mut Entity<A>) -> Self {
564-
unsafe {
565-
// SAFETY: Entity<A> is a transparent struct containing only an EntityAny,
566-
// which guarantees that they have the same representation in memory
567-
mem::transmute(value)
568-
}
555+
&mut value.inner
569556
}
570557
}
571558

572559
impl<'a, A: Archetype> From<&'a mut EntityDirect<A>> for &'a mut EntityDirectAny {
573560
#[inline(always)]
574561
fn from(value: &'a mut EntityDirect<A>) -> Self {
575-
unsafe {
576-
// SAFETY: EntityDirect<A> is a transparent struct containing only an EntityDirectAny,
577-
// which guarantees that they have the same representation in memory
578-
mem::transmute(value)
579-
}
562+
&mut value.inner
580563
}
581564
}
582565

0 commit comments

Comments
 (0)