Skip to content

Commit e72afde

Browse files
m-ou-seMark-Simulacrum
authored andcommitted
Add Pin::static_mut.
1 parent 41eb822 commit e72afde

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/core/src/pin.rs

+14
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,20 @@ impl<T: ?Sized> Pin<&'static T> {
795795
}
796796
}
797797

798+
impl<T: ?Sized> Pin<&'static T> {
799+
/// Get a pinned mutable reference from a static mutable reference.
800+
///
801+
/// This is safe, because the `'static` lifetime guarantees the data will
802+
/// never be moved.
803+
#[unstable(feature = "pin_static_ref", issue = "none")]
804+
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
805+
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
806+
// SAFETY: The 'static lifetime guarantees the data will not be
807+
// moved/invalidated until it gets dropped (which is never).
808+
unsafe { Pin::new_unchecked(r) }
809+
}
810+
}
811+
798812
#[stable(feature = "pin", since = "1.33.0")]
799813
impl<P: Deref> Deref for Pin<P> {
800814
type Target = P::Target;

0 commit comments

Comments
 (0)