Diffstat (limited to 'src/any/indirect.rs')
-rw-r--r--src/any/indirect.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/any/indirect.rs b/src/any/indirect.rs
index f337e02..2b4eccd 100644
--- a/src/any/indirect.rs
+++ b/src/any/indirect.rs
@@ -32,6 +32,7 @@ pub(super) mod sealed {
/// `value` must have been created by `Self::into_raw`.
/// This function must not be called twice for the same `value`.
/// The type `T` must be the one given to `Self::into_raw`.
+ #[allow(unsafe_code)]
unsafe fn from_raw<T: ?Sized + 'a>(
value: MaybeUninit<[u8; INDIRECT_SIZE]>,
) -> Self::ForT<T>;
@@ -58,6 +59,7 @@ pub(super) mod sealed {
/// # Safety
/// The type `T` must be the same one used in `Self::new`.
+ #[allow(unsafe_code)]
pub unsafe fn into_inner<T: ?Sized>(self) -> I::ForT<T> {
// SAFETY: indirect was created with this I's into_raw in Self::new.
// This function cannot be called twice because we take ownership of self and
@@ -94,9 +96,11 @@ pub(super) mod sealed {
impl<'a> Sealed<'a> for Ref {
fn into_raw<T: ?Sized + 'a>(value: Self::ForT<T>) -> MaybeUninit<[u8; INDIRECT_SIZE]> {
// SAFETY: A possibly fat borrow can be stores in a 2 usize wide maybe uninit array.
+ #[allow(unsafe_code)]
unsafe { transmute::<&'a T, MaybeUninit<[u8; INDIRECT_SIZE]>>(value) }
}
+ #[allow(unsafe_code)]
unsafe fn from_raw<T: ?Sized + 'a>(any: MaybeUninit<[u8; INDIRECT_SIZE]>) -> Self::ForT<T> {
// SAFETY: We know the value is from Self::into_raw because of the caller invariants.
unsafe { transmute::<MaybeUninit<[u8; INDIRECT_SIZE]>, &'a T>(any) }
@@ -106,9 +110,11 @@ pub(super) mod sealed {
impl<'a> Sealed<'a> for Mut {
fn into_raw<T: ?Sized + 'a>(value: Self::ForT<T>) -> MaybeUninit<[u8; INDIRECT_SIZE]> {
// SAFETY: A possibly fat borrow can be stores in a 2 usize wide maybe uninit array.
+ #[allow(unsafe_code)]
unsafe { transmute::<&'a mut T, MaybeUninit<[u8; INDIRECT_SIZE]>>(value) }
}
+ #[allow(unsafe_code)]
unsafe fn from_raw<T: ?Sized + 'a>(any: MaybeUninit<[u8; INDIRECT_SIZE]>) -> Self::ForT<T> {
// SAFETY: We know the value is from Self::into_raw because of the caller invariants.
unsafe { transmute::<MaybeUninit<[u8; INDIRECT_SIZE]>, &'a mut T>(any) }
@@ -136,6 +142,7 @@ impl<'a> Indirect<'a> for Mut {}
/// # Safety
/// Same rules as [`core::mem::transmute()`].
+#[allow(unsafe_code)]
unsafe fn transmute<T, U>(value: T) -> U {
// Create union type that can store a `T` or a `U`.
// We can then use this to convert between them.
@@ -173,6 +180,7 @@ mod test {
let z = RawIndirect::<Ref>::new(y);
// SAFETY: Same type as y which we made it from.
+ #[allow(unsafe_code)]
let w: &i32 = unsafe { z.into_inner() };
assert_eq!(w, y);
@@ -195,6 +203,7 @@ mod test {
let z = RawIndirect::<Ref>::new(y);
// SAFETY: Same type as y which we made it from.
+ #[allow(unsafe_code)]
let w: &i32 = unsafe { z.into_inner() };
assert_eq!(w.as_int(), x);
@@ -207,6 +216,7 @@ mod test {
let z = RawIndirect::<Mut>::new(y);
// SAFETY: Same type as y which we made it from.
+ #[allow(unsafe_code)]
let w: &mut i32 = unsafe { z.into_inner() };
*w += 1;
@@ -230,6 +240,7 @@ mod test {
let z = RawIndirect::<Mut>::new(y);
// SAFETY: Same type as y which we made it from.
+ #[allow(unsafe_code)]
let w: &mut dyn AddOne = unsafe { z.into_inner() };
w.add_one();