Rollup merge of #130136 - GKFX:stabilize-const-pin, r=dtolnay
Partially stabilize const_pin Tracking issue #76654. Eight of these methods can be made const-stable. The remainder are blocked on #73255.
This commit is contained in:
commit
dae3076fa2
@ -112,7 +112,6 @@
|
|||||||
#![feature(const_eval_select)]
|
#![feature(const_eval_select)]
|
||||||
#![feature(const_heap)]
|
#![feature(const_heap)]
|
||||||
#![feature(const_maybe_uninit_write)]
|
#![feature(const_maybe_uninit_write)]
|
||||||
#![feature(const_pin)]
|
|
||||||
#![feature(const_size_of_val)]
|
#![feature(const_size_of_val)]
|
||||||
#![feature(const_vec_string_slice)]
|
#![feature(const_vec_string_slice)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
@ -129,7 +129,7 @@
|
|||||||
#![feature(const_nonnull_new)]
|
#![feature(const_nonnull_new)]
|
||||||
#![feature(const_num_midpoint)]
|
#![feature(const_num_midpoint)]
|
||||||
#![feature(const_option_ext)]
|
#![feature(const_option_ext)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin_2)]
|
||||||
#![feature(const_pointer_is_aligned)]
|
#![feature(const_pointer_is_aligned)]
|
||||||
#![feature(const_ptr_is_null)]
|
#![feature(const_ptr_is_null)]
|
||||||
#![feature(const_ptr_sub_ptr)]
|
#![feature(const_ptr_sub_ptr)]
|
||||||
|
@ -1186,7 +1186,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
|
|||||||
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
|
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
|
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
|
||||||
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
|
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
|
||||||
@ -1214,7 +1214,7 @@ pub const fn new(pointer: Ptr) -> Pin<Ptr> {
|
|||||||
/// assert_eq!(*r, 5);
|
/// assert_eq!(*r, 5);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
|
||||||
#[stable(feature = "pin_into_inner", since = "1.39.0")]
|
#[stable(feature = "pin_into_inner", since = "1.39.0")]
|
||||||
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
|
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
|
||||||
pin.__pointer
|
pin.__pointer
|
||||||
@ -1351,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
|
|||||||
/// [`pin` module docs]: self
|
/// [`pin` module docs]: self
|
||||||
#[lang = "new_unchecked"]
|
#[lang = "new_unchecked"]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
|
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
|
||||||
Pin { __pointer: pointer }
|
Pin { __pointer: pointer }
|
||||||
@ -1503,7 +1503,7 @@ impl<Ptr: Deref> Pin<Ptr> {
|
|||||||
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
|
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
|
||||||
/// instead.
|
/// instead.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
|
||||||
#[stable(feature = "pin_into_inner", since = "1.39.0")]
|
#[stable(feature = "pin_into_inner", since = "1.39.0")]
|
||||||
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
|
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
|
||||||
pin.__pointer
|
pin.__pointer
|
||||||
@ -1559,7 +1559,7 @@ pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
|
|||||||
/// ["pinning projections"]: self#projections-and-structural-pinning
|
/// ["pinning projections"]: self#projections-and-structural-pinning
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub const fn get_ref(self) -> &'a T {
|
pub const fn get_ref(self) -> &'a T {
|
||||||
self.__pointer
|
self.__pointer
|
||||||
@ -1570,7 +1570,7 @@ 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)]
|
||||||
#[must_use = "`self` will be dropped if the result is not used"]
|
#[must_use = "`self` will be dropped if the result is not used"]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub const fn into_ref(self) -> Pin<&'a T> {
|
pub const fn into_ref(self) -> Pin<&'a T> {
|
||||||
Pin { __pointer: self.__pointer }
|
Pin { __pointer: self.__pointer }
|
||||||
@ -1588,7 +1588,7 @@ pub const fn into_ref(self) -> Pin<&'a T> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use = "`self` will be dropped if the result is not used"]
|
#[must_use = "`self` will be dropped if the result is not used"]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const fn get_mut(self) -> &'a mut T
|
pub const fn get_mut(self) -> &'a mut T
|
||||||
where
|
where
|
||||||
T: Unpin,
|
T: Unpin,
|
||||||
@ -1609,7 +1609,7 @@ pub const fn get_mut(self) -> &'a mut T
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use = "`self` will be dropped if the result is not used"]
|
#[must_use = "`self` will be dropped if the result is not used"]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
|
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
|
||||||
self.__pointer
|
self.__pointer
|
||||||
}
|
}
|
||||||
@ -1652,7 +1652,7 @@ impl<T: ?Sized> Pin<&'static T> {
|
|||||||
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
|
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
|
||||||
/// never ends.
|
/// never ends.
|
||||||
#[stable(feature = "pin_static_ref", since = "1.61.0")]
|
#[stable(feature = "pin_static_ref", since = "1.61.0")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
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 borrow 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).
|
||||||
@ -1666,7 +1666,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
|
|||||||
/// This is safe because `T` is borrowed for the `'static` lifetime, which
|
/// This is safe because `T` is borrowed for the `'static` lifetime, which
|
||||||
/// never ends.
|
/// never ends.
|
||||||
#[stable(feature = "pin_static_ref", since = "1.61.0")]
|
#[stable(feature = "pin_static_ref", since = "1.61.0")]
|
||||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
|
||||||
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 borrow 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).
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#![feature(const_likely)]
|
#![feature(const_likely)]
|
||||||
#![feature(const_nonnull_new)]
|
#![feature(const_nonnull_new)]
|
||||||
#![feature(const_option_ext)]
|
#![feature(const_option_ext)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin_2)]
|
||||||
#![feature(const_pointer_is_aligned)]
|
#![feature(const_pointer_is_aligned)]
|
||||||
#![feature(const_three_way_compare)]
|
#![feature(const_three_way_compare)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
@ -19,6 +19,10 @@ fn pin_const() {
|
|||||||
const REF: &'static usize = PINNED.get_ref();
|
const REF: &'static usize = PINNED.get_ref();
|
||||||
assert_eq!(REF, POINTER);
|
assert_eq!(REF, POINTER);
|
||||||
|
|
||||||
|
const INT: u8 = 42;
|
||||||
|
const STATIC_REF: Pin<&'static u8> = Pin::static_ref(&INT);
|
||||||
|
assert_eq!(*STATIC_REF, INT);
|
||||||
|
|
||||||
// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
|
// 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.
|
// A const fn is used because `&mut` is not (yet) usable in constants.
|
||||||
const fn pin_mut_const() {
|
const fn pin_mut_const() {
|
||||||
|
Loading…
Reference in New Issue
Block a user