Make some methods of Pin<&mut T>
unstable const
Make the following methods unstable const under the `const_pin` feature: - `into_ref` - `get_mut` - `get_unchecked_mut`
This commit is contained in:
parent
8f27e3cb1b
commit
e3c6e46168
@ -708,8 +708,9 @@ pub const fn get_ref(self) -> &'a T {
|
|||||||
impl<'a, T: ?Sized> Pin<&'a mut T> {
|
impl<'a, T: ?Sized> Pin<&'a mut T> {
|
||||||
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
|
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub fn into_ref(self) -> Pin<&'a T> {
|
pub const fn into_ref(self) -> Pin<&'a T> {
|
||||||
Pin { pointer: self.pointer }
|
Pin { pointer: self.pointer }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,9 +723,10 @@ pub fn into_ref(self) -> Pin<&'a T> {
|
|||||||
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
|
/// 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
|
/// the `Pin` itself. This method allows turning the `Pin` into a reference
|
||||||
/// with the same lifetime as the original `Pin`.
|
/// with the same lifetime as the original `Pin`.
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
|
||||||
#[inline(always)]
|
#[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
|
where
|
||||||
T: Unpin,
|
T: Unpin,
|
||||||
{
|
{
|
||||||
@ -741,9 +743,10 @@ pub fn get_mut(self) -> &'a mut T
|
|||||||
///
|
///
|
||||||
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
|
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
|
||||||
/// instead.
|
/// instead.
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
|
||||||
#[inline(always)]
|
#[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
|
self.pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#![feature(iter_order_by)]
|
#![feature(iter_order_by)]
|
||||||
#![feature(cmp_min_max_by)]
|
#![feature(cmp_min_max_by)]
|
||||||
#![feature(iter_map_while)]
|
#![feature(iter_map_while)]
|
||||||
|
#![feature(const_mut_refs)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_slice_from_raw_parts)]
|
#![feature(const_slice_from_raw_parts)]
|
||||||
#![feature(const_raw_ptr_deref)]
|
#![feature(const_raw_ptr_deref)]
|
||||||
|
@ -17,5 +17,15 @@ fn pin_const() {
|
|||||||
assert_eq!(INNER_UNCHECKED, POINTER);
|
assert_eq!(INNER_UNCHECKED, POINTER);
|
||||||
|
|
||||||
const REF: &'static usize = PINNED.get_ref();
|
const REF: &'static usize = PINNED.get_ref();
|
||||||
assert_eq!(REF, POINTER)
|
assert_eq!(REF, POINTER);
|
||||||
|
|
||||||
|
// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
|
||||||
|
// A const fn is used because `&mut` is not (yet) usable in constants.
|
||||||
|
const fn pin_mut_const() {
|
||||||
|
let _ = Pin::new(&mut 2).into_ref();
|
||||||
|
let _ = Pin::new(&mut 2).get_mut();
|
||||||
|
let _ = unsafe { Pin::new(&mut 2).get_unchecked_mut() };
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_mut_const();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user