From a1ff76776ced4e34f7c1e612292e2eb40091f74a Mon Sep 17 00:00:00 2001 From: iris <2+iris@noreply.localhost> Date: Sun, 13 Sep 2026 00:58:56 -0400 Subject: [PATCH] Keep unsafe reference helpers internal --- core/src/util/trust.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/src/util/trust.rs b/core/src/util/trust.rs index b9d1a6b..fc48c17 100644 --- a/core/src/util/trust.rs +++ b/core/src/util/trust.rs @@ -1,15 +1,26 @@ -#[allow(clippy::missing_safety_doc)] -pub unsafe fn forget_ref<'a, T>(x: &T) -> &'a T { +/// Extends a shared reference's lifetime. +/// +/// # Safety +/// The pointee must remain alive and shared-borrowed for all of `'a`. +pub(crate) unsafe fn forget_ref<'a, T>(x: &T) -> &'a T { unsafe { std::mem::transmute::<&T, &T>(x) } } -#[allow(clippy::missing_safety_doc)] -pub unsafe fn forget_mut<'a, T>(x: &mut T) -> &'a mut T { +/// Extends an exclusive reference's lifetime. +/// +/// # Safety +/// The pointee must remain alive and exclusively borrowed for all of `'a`. +pub(crate) unsafe fn forget_mut<'a, T>(x: &mut T) -> &'a mut T { unsafe { std::mem::transmute::<&mut T, &mut T>(x) } } -#[allow(clippy::mut_from_ref, clippy::missing_safety_doc)] -pub unsafe fn to_mut(x: &T) -> &mut T { +/// Converts a shared reference into an exclusive reference. +/// +/// # Safety +/// The caller must have exclusive access to the pointee for the returned +/// reference's lifetime. +#[allow(clippy::mut_from_ref)] +pub(crate) unsafe fn to_mut(x: &T) -> &mut T { #[allow(mutable_transmutes)] unsafe { std::mem::transmute::<&T, &mut T>(x)