///
/// Unlike `Pin::new_unchecked`, this method is safe because the pointer
/// `P` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
- #[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
- pub fn new(pointer: P) -> Pin<P> {
- // Safety: the value pointed to is `Unpin`, and so has no requirements
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin", since = "1.33.0")]
+ pub const fn new(pointer: P) -> Pin<P> {
+ // SAFETY: the value pointed to is `Unpin`, and so has no requirements
// around pinning.
unsafe { Pin::new_unchecked(pointer) }
}
///
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
/// can ignore the pinning invariants when unwrapping it.
- #[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
- pub fn into_inner(pin: Pin<P>) -> P {
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin_into_inner", since = "1.39.0")]
+ pub const fn into_inner(pin: Pin<P>) -> P {
pin.pointer
}
}
/// use std::pin::Pin;
///
/// fn move_pinned_rc<T>(mut x: Rc<T>) {
- /// let pinned = unsafe { Pin::new_unchecked(x.clone()) };
+ /// let pinned = unsafe { Pin::new_unchecked(Rc::clone(&x)) };
/// {
/// let p: Pin<&T> = pinned.as_ref();
/// // This should mean the pointee can never move again.
/// ```
///
/// [`mem::swap`]: crate::mem::swap
- #[cfg_attr(not(bootstrap), lang = "new_unchecked")]
- #[stable(feature = "pin", since = "1.33.0")]
+ #[lang = "new_unchecked"]
#[inline(always)]
- pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin", since = "1.33.0")]
+ pub const unsafe fn new_unchecked(pointer: P) -> Pin<P> {
Pin { pointer }
}
///
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
/// instead.
- #[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
- pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin_into_inner", since = "1.39.0")]
+ pub const unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
pin.pointer
}
}
/// because it is one of the fields of that value), and also that you do
/// not move out of the argument you receive to the interior function.
///
- /// [`pin` module]: ../../std/pin/index.html#projections-and-structural-pinning
+ /// [`pin` module]: self#projections-and-structural-pinning
#[stable(feature = "pin", since = "1.33.0")]
pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
where
/// the `Pin` itself. This method allows turning the `Pin` into a reference
/// with the same lifetime as the original `Pin`.
///
- /// ["pinning projections"]: ../../std/pin/index.html#projections-and-structural-pinning
- #[stable(feature = "pin", since = "1.33.0")]
+ /// ["pinning projections"]: self#projections-and-structural-pinning
#[inline(always)]
- pub fn get_ref(self) -> &'a T {
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin", since = "1.33.0")]
+ pub const fn get_ref(self) -> &'a T {
self.pointer
}
}
impl<'a, T: ?Sized> Pin<&'a mut T> {
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
- #[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
- pub fn into_ref(self) -> Pin<&'a T> {
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ #[stable(feature = "pin", since = "1.33.0")]
+ pub const fn into_ref(self) -> Pin<&'a T> {
Pin { pointer: self.pointer }
}
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
/// the `Pin` itself. This method allows turning the `Pin` into a reference
/// with the same lifetime as the original `Pin`.
- #[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
- pub fn get_mut(self) -> &'a mut T
+ #[stable(feature = "pin", since = "1.33.0")]
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ pub const fn get_mut(self) -> &'a mut T
where
T: Unpin,
{
///
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
/// instead.
- #[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
- pub unsafe fn get_unchecked_mut(self) -> &'a mut T {
+ #[stable(feature = "pin", since = "1.33.0")]
+ #[rustc_const_unstable(feature = "const_pin", issue = "76654")]
+ pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
self.pointer
}
/// because it is one of the fields of that value), and also that you do
/// not move out of the argument you receive to the interior function.
///
- /// [`pin` module]: ../../std/pin/index.html#projections-and-structural-pinning
+ /// [`pin` module]: self#projections-and-structural-pinning
#[stable(feature = "pin", since = "1.33.0")]
pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U>
where