Keep unsafe reference helpers internal
This commit is contained in:
1 parent
db9b0f21d5
commit
a1ff76776c
1 file changed
+17
-6
+17
-6
@@ -1,15 +1,26 @@
|
|||||||
#[allow(clippy::missing_safety_doc)]
|
/// Extends a shared reference's lifetime.
|
||||||
pub unsafe fn forget_ref<'a, T>(x: &T) -> &'a T {
|
///
|
||||||
|
/// # 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) }
|
unsafe { std::mem::transmute::<&T, &T>(x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::missing_safety_doc)]
|
/// Extends an exclusive reference's lifetime.
|
||||||
pub unsafe fn forget_mut<'a, T>(x: &mut T) -> &'a mut T {
|
///
|
||||||
|
/// # 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) }
|
unsafe { std::mem::transmute::<&mut T, &mut T>(x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::mut_from_ref, clippy::missing_safety_doc)]
|
/// Converts a shared reference into an exclusive reference.
|
||||||
pub unsafe fn to_mut<T>(x: &T) -> &mut T {
|
///
|
||||||
|
/// # 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)]
|
#[allow(mutable_transmutes)]
|
||||||
unsafe {
|
unsafe {
|
||||||
std::mem::transmute::<&T, &mut T>(x)
|
std::mem::transmute::<&T, &mut T>(x)
|
||||||
|
|||||||
Reference in new issue
Block a user