Reword safety guarantee of Pin::static_{ref,mut}.
Co-authored-by: Peter Todd <pete@petertodd.org>
This commit is contained in:
@@ -784,12 +784,12 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
|
|||||||
impl<T: ?Sized> Pin<&'static T> {
|
impl<T: ?Sized> Pin<&'static T> {
|
||||||
/// Get a pinned reference from a static reference.
|
/// Get a pinned reference from a static reference.
|
||||||
///
|
///
|
||||||
/// This is safe, because the `'static` lifetime guarantees the data will
|
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
|
||||||
/// never be moved.
|
/// never ends.
|
||||||
#[unstable(feature = "pin_static_ref", issue = "none")]
|
#[unstable(feature = "pin_static_ref", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||||
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
|
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
|
||||||
// SAFETY: The 'static lifetime guarantees the data will not be
|
// SAFETY: The 'static borrow guarantees the data will not be
|
||||||
// moved/invalidated until it gets dropped (which is never).
|
// moved/invalidated until it gets dropped (which is never).
|
||||||
unsafe { Pin::new_unchecked(r) }
|
unsafe { Pin::new_unchecked(r) }
|
||||||
}
|
}
|
||||||
@@ -798,12 +798,12 @@ impl<T: ?Sized> Pin<&'static T> {
|
|||||||
impl<T: ?Sized> Pin<&'static T> {
|
impl<T: ?Sized> Pin<&'static T> {
|
||||||
/// Get a pinned mutable reference from a static mutable reference.
|
/// Get a pinned mutable reference from a static mutable reference.
|
||||||
///
|
///
|
||||||
/// This is safe, because the `'static` lifetime guarantees the data will
|
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
|
||||||
/// never be moved.
|
/// never ends.
|
||||||
#[unstable(feature = "pin_static_ref", issue = "none")]
|
#[unstable(feature = "pin_static_ref", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||||
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
|
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
|
||||||
// SAFETY: The 'static lifetime guarantees the data will not be
|
// SAFETY: The 'static borrow guarantees the data will not be
|
||||||
// moved/invalidated until it gets dropped (which is never).
|
// moved/invalidated until it gets dropped (which is never).
|
||||||
unsafe { Pin::new_unchecked(r) }
|
unsafe { Pin::new_unchecked(r) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user