Skip to content

Commit

Permalink
Backport the reimplementation of transmute
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk20 committed Mar 2, 2021
1 parent fa46b38 commit 5b6d0e8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib.rs
Expand Up @@ -53,7 +53,6 @@ use core::{mem, ptr, slice};

use core::marker::PhantomData;
use core::mem::ManuallyDrop;
pub use core::mem::transmute;
use core::ops::{Deref, DerefMut};

use typenum::bit::{B0, B1};
Expand Down Expand Up @@ -435,6 +434,16 @@ where
}
}

/// A reimplementation of the `transmute` function, avoiding problems
/// when the compiler can't prove equal sizes.
#[inline]
#[doc(hidden)]
pub unsafe fn transmute<A, B>(a: A) -> B {
let b = ::core::ptr::read(&a as *const A as *const B);
::core::mem::forget(a);
b
}

#[cfg(test)]
mod test {
// Compile with:
Expand Down

0 comments on commit 5b6d0e8

Please sign in to comment.