Keep unsafe reference helpers internal

This commit is contained in:
iris committed 2026-09-13 00:58:56 -04:00
1 parent db9b0f21d5
commit a1ff76776c
1 file changed
+17 -6
+17 -6
View File
@@ -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<T>(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<T>(x: &T) -> &mut T {
#[allow(mutable_transmutes)]
unsafe {
std::mem::transmute::<&T, &mut T>(x)