about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-10-12 20:00:56 +0200
committerMara Bos <m-ou.se@m-ou.se>2020-10-12 20:00:56 +0200
commit2c71f682d74d13ae6673dc701a9bb3a0562f57c0 (patch)
tree033bab83210827edae513f6ff2fa58c4a2fd3d0b
parent104c0f0194177442ff16cf14907a96d2f8d200dd (diff)
downloadrust-2c71f682d74d13ae6673dc701a9bb3a0562f57c0.tar.gz
rust-2c71f682d74d13ae6673dc701a9bb3a0562f57c0.zip
Add Pin::static_mut.
-rw-r--r--library/core/src/pin.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index 9e2d64a866f..b27167a7e7c 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -795,6 +795,20 @@ impl<T: ?Sized> Pin<&'static T> {
     }
 }
 
+impl<T: ?Sized> Pin<&'static T> {
+    /// Get a pinned mutable reference from a static mutable reference.
+    ///
+    /// This is safe, because the `'static` lifetime guarantees the data will
+    /// never be moved.
+    #[unstable(feature = "pin_static_ref", issue = "none")]
+    #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+    pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
+        // SAFETY: The 'static lifetime guarantees the data will not be
+        // moved/invalidated until it gets dropped (which is never).
+        unsafe { Pin::new_unchecked(r) }
+    }
+}
+
 #[stable(feature = "pin", since = "1.33.0")]
 impl<P: Deref> Deref for Pin<P> {
     type Target = P::Target;