Skip to content

Commit c55b659

Browse files
committed
Partially stabilize const_pin
1 parent dde7d66 commit c55b659

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
#![feature(const_maybe_uninit_as_mut_ptr)]
114114
#![feature(const_maybe_uninit_write)]
115115
#![feature(const_option)]
116-
#![feature(const_pin)]
117116
#![feature(const_size_of_val)]
118117
#![feature(core_intrinsics)]
119118
#![feature(deprecated_suggestion)]

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
#![feature(const_num_midpoint)]
138138
#![feature(const_option)]
139139
#![feature(const_option_ext)]
140-
#![feature(const_pin)]
140+
#![feature(const_pin_2)]
141141
#![feature(const_pointer_is_aligned)]
142142
#![feature(const_ptr_as_ref)]
143143
#![feature(const_ptr_is_null)]

library/core/src/pin.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
11861186
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
11871187
/// ```
11881188
#[inline(always)]
1189-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1189+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
11901190
#[stable(feature = "pin", since = "1.33.0")]
11911191
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
11921192
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
@@ -1214,7 +1214,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
12141214
/// assert_eq!(*r, 5);
12151215
/// ```
12161216
#[inline(always)]
1217-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1217+
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
12181218
#[stable(feature = "pin_into_inner", since = "1.39.0")]
12191219
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
12201220
pin.__pointer
@@ -1351,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13511351
/// [`pin` module docs]: self
13521352
#[lang = "new_unchecked"]
13531353
#[inline(always)]
1354-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1354+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
13551355
#[stable(feature = "pin", since = "1.33.0")]
13561356
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
13571357
Pin { __pointer: pointer }
@@ -1503,7 +1503,7 @@ impl<Ptr: Deref> Pin<Ptr> {
15031503
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
15041504
/// instead.
15051505
#[inline(always)]
1506-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1506+
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
15071507
#[stable(feature = "pin_into_inner", since = "1.39.0")]
15081508
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
15091509
pin.__pointer
@@ -1559,7 +1559,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
15591559
/// ["pinning projections"]: self#projections-and-structural-pinning
15601560
#[inline(always)]
15611561
#[must_use]
1562-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1562+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15631563
#[stable(feature = "pin", since = "1.33.0")]
15641564
pub const fn get_ref(self) -> &'a T {
15651565
self.__pointer
@@ -1570,7 +1570,8 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15701570
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
15711571
#[inline(always)]
15721572
#[must_use = "`self` will be dropped if the result is not used"]
1573-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1573+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
1574+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15741575
#[stable(feature = "pin", since = "1.33.0")]
15751576
pub const fn into_ref(self) -> Pin<&'a T> {
15761577
Pin { __pointer: self.__pointer }
@@ -1587,8 +1588,9 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15871588
/// with the same lifetime as the original `Pin`.
15881589
#[inline(always)]
15891590
#[must_use = "`self` will be dropped if the result is not used"]
1591+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
15901592
#[stable(feature = "pin", since = "1.33.0")]
1591-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1593+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15921594
pub const fn get_mut(self) -> &'a mut T
15931595
where
15941596
T: Unpin,
@@ -1608,8 +1610,9 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
16081610
/// instead.
16091611
#[inline(always)]
16101612
#[must_use = "`self` will be dropped if the result is not used"]
1613+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
16111614
#[stable(feature = "pin", since = "1.33.0")]
1612-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1615+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16131616
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
16141617
self.__pointer
16151618
}
@@ -1652,7 +1655,7 @@ impl<T: ?Sized> Pin<&'static T> {
16521655
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
16531656
/// never ends.
16541657
#[stable(feature = "pin_static_ref", since = "1.61.0")]
1655-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1658+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16561659
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
16571660
// SAFETY: The 'static borrow guarantees the data will not be
16581661
// moved/invalidated until it gets dropped (which is never).
@@ -1665,8 +1668,9 @@ impl<T: ?Sized> Pin<&'static mut T> {
16651668
///
16661669
/// This is safe because `T` is borrowed for the `'static` lifetime, which
16671670
/// never ends.
1671+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
16681672
#[stable(feature = "pin_static_ref", since = "1.61.0")]
1669-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1673+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16701674
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
16711675
// SAFETY: The 'static borrow guarantees the data will not be
16721676
// moved/invalidated until it gets dropped (which is never).

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#![feature(const_nonnull_new)]
3131
#![feature(const_option)]
3232
#![feature(const_option_ext)]
33-
#![feature(const_pin)]
33+
#![feature(const_pin_2)]
3434
#![feature(const_pointer_is_aligned)]
3535
#![feature(const_ptr_as_ref)]
3636
#![feature(const_ptr_write)]

library/core/tests/pin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ fn pin_const() {
1919
const REF: &'static usize = PINNED.get_ref();
2020
assert_eq!(REF, POINTER);
2121

22+
const INT: u8 = 42;
23+
const STATIC_REF: Pin<&'static u8> = Pin::static_ref(&INT);
24+
assert_eq!(*STATIC_REF, INT);
25+
2226
// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
2327
// A const fn is used because `&mut` is not (yet) usable in constants.
2428
const fn pin_mut_const() {

0 commit comments

Comments
 (0)