Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c99bba3

Browse files
committedApr 28, 2024
Auto merge of #124498 - tgross35:stabilize-non_null_convenience, r=jhpratt
Stabilize `non_null_convenience` Fully stabilize the following API, including const where applicable: ```rust impl <T> NonNull<T> { pub const unsafe fn offset(self, count: isize) -> Self; pub const unsafe fn add(self, count: usize) -> Self; pub const unsafe fn sub(self, count: usize) -> Self; pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize; pub const unsafe fn read(self) -> T; pub unsafe fn read_volatile(self) -> T; pub const unsafe fn read_unaligned(self) -> T; pub unsafe fn write_volatile(self, val: T); pub unsafe fn replace(self, src: T) -> T; } impl<T: ?Sized> NonNull<T> { pub const unsafe fn byte_offset(self, count: isize) -> Self; pub const unsafe fn byte_add(self, count: usize) -> Self; pub const unsafe fn byte_sub(self, count: usize) -> Self; pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize; pub unsafe fn drop_in_place(self); } ``` Stabilize the following without const: ```rust impl <T> NonNull<T> { // const under `const_intrinsic_copy` pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize); pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize); // const under `const_ptr_write` pub const unsafe fn write(self, val: T); pub const unsafe fn write_bytes(self, val: u8, count: usize); pub const unsafe fn write_unaligned(self, val: T); // const under `const_swap` pub const unsafe fn swap(self, with: NonNull<T>); // const under `const_align_offset` pub const fn align_offset(self, align: usize) -> usize; // const under `const_pointer_is_aligned` pub const fn is_aligned(self) -> bool; } ``` Left the following unstable: ```rust impl <T> NonNull<T> { // moved gate to `ptr_sub_ptr` pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize; } impl <T: ?Sized> NonNull<T> { // moved gate to `pointer_is_aligned_to` pub const fn is_aligned_to(self, align: usize) -> bool; } ``` Fixes: #117691
2 parents 1fffb2a + e0f8202 commit c99bba3

File tree

3 files changed

+63
-79
lines changed

3 files changed

+63
-79
lines changed
 

‎library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
#![feature(maybe_uninit_slice)]
138138
#![feature(maybe_uninit_uninit_array)]
139139
#![feature(maybe_uninit_uninit_array_transpose)]
140-
#![feature(non_null_convenience)]
141140
#![feature(panic_internals)]
142141
#![feature(pattern)]
143142
#![feature(ptr_internals)]

‎library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
#![feature(isqrt)]
181181
#![feature(link_cfg)]
182182
#![feature(maybe_uninit_uninit_array)]
183-
#![feature(non_null_convenience)]
184183
#![feature(offset_of_enum)]
185184
#![feature(offset_of_nested)]
186185
#![feature(panic_internals)]

‎library/core/src/ptr/non_null.rs

Lines changed: 63 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ impl<T: ?Sized> NonNull<T> {
512512
/// # Examples
513513
///
514514
/// ```
515-
/// #![feature(non_null_convenience)]
516515
/// use std::ptr::NonNull;
517516
///
518517
/// let mut s = [1, 2, 3];
@@ -523,12 +522,12 @@ impl<T: ?Sized> NonNull<T> {
523522
/// println!("{}", ptr.offset(2).read());
524523
/// }
525524
/// ```
526-
#[unstable(feature = "non_null_convenience", issue = "117691")]
527-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
528-
#[must_use = "returns a new pointer rather than modifying its argument"]
529525
#[inline(always)]
530526
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
531-
pub const unsafe fn offset(self, count: isize) -> NonNull<T>
527+
#[must_use = "returns a new pointer rather than modifying its argument"]
528+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
529+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
530+
pub const unsafe fn offset(self, count: isize) -> Self
532531
where
533532
T: Sized,
534533
{
@@ -549,11 +548,11 @@ impl<T: ?Sized> NonNull<T> {
549548
///
550549
/// For non-`Sized` pointees this operation changes only the data pointer,
551550
/// leaving the metadata untouched.
552-
#[unstable(feature = "non_null_convenience", issue = "117691")]
553-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
554551
#[must_use]
555552
#[inline(always)]
556553
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
554+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
555+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
557556
pub const unsafe fn byte_offset(self, count: isize) -> Self {
558557
// SAFETY: the caller must uphold the safety contract for `offset` and `byte_offset` has
559558
// the same safety contract.
@@ -599,7 +598,6 @@ impl<T: ?Sized> NonNull<T> {
599598
/// # Examples
600599
///
601600
/// ```
602-
/// #![feature(non_null_convenience)]
603601
/// use std::ptr::NonNull;
604602
///
605603
/// let s: &str = "123";
@@ -610,11 +608,11 @@ impl<T: ?Sized> NonNull<T> {
610608
/// println!("{}", ptr.add(2).read() as char);
611609
/// }
612610
/// ```
613-
#[unstable(feature = "non_null_convenience", issue = "117691")]
614-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
615-
#[must_use = "returns a new pointer rather than modifying its argument"]
616611
#[inline(always)]
617612
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
613+
#[must_use = "returns a new pointer rather than modifying its argument"]
614+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
615+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
618616
pub const unsafe fn add(self, count: usize) -> Self
619617
where
620618
T: Sized,
@@ -636,12 +634,12 @@ impl<T: ?Sized> NonNull<T> {
636634
///
637635
/// For non-`Sized` pointees this operation changes only the data pointer,
638636
/// leaving the metadata untouched.
639-
#[unstable(feature = "non_null_convenience", issue = "117691")]
640-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
641637
#[must_use]
642638
#[inline(always)]
643-
#[rustc_allow_const_fn_unstable(set_ptr_value)]
644639
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
640+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
641+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
642+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
645643
pub const unsafe fn byte_add(self, count: usize) -> Self {
646644
// SAFETY: the caller must uphold the safety contract for `add` and `byte_add` has the same
647645
// safety contract.
@@ -688,7 +686,6 @@ impl<T: ?Sized> NonNull<T> {
688686
/// # Examples
689687
///
690688
/// ```
691-
/// #![feature(non_null_convenience)]
692689
/// use std::ptr::NonNull;
693690
///
694691
/// let s: &str = "123";
@@ -699,11 +696,11 @@ impl<T: ?Sized> NonNull<T> {
699696
/// println!("{}", end.sub(2).read() as char);
700697
/// }
701698
/// ```
702-
#[unstable(feature = "non_null_convenience", issue = "117691")]
703-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
704-
#[must_use = "returns a new pointer rather than modifying its argument"]
705699
#[inline(always)]
706700
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
701+
#[must_use = "returns a new pointer rather than modifying its argument"]
702+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
703+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
707704
pub const unsafe fn sub(self, count: usize) -> Self
708705
where
709706
T: Sized,
@@ -730,12 +727,12 @@ impl<T: ?Sized> NonNull<T> {
730727
///
731728
/// For non-`Sized` pointees this operation changes only the data pointer,
732729
/// leaving the metadata untouched.
733-
#[unstable(feature = "non_null_convenience", issue = "117691")]
734-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
735730
#[must_use]
736731
#[inline(always)]
737-
#[rustc_allow_const_fn_unstable(set_ptr_value)]
738732
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
733+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
734+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
735+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
739736
pub const unsafe fn byte_sub(self, count: usize) -> Self {
740737
// SAFETY: the caller must uphold the safety contract for `sub` and `byte_sub` has the same
741738
// safety contract.
@@ -816,7 +813,6 @@ impl<T: ?Sized> NonNull<T> {
816813
/// Basic usage:
817814
///
818815
/// ```
819-
/// #![feature(non_null_convenience)]
820816
/// use std::ptr::NonNull;
821817
///
822818
/// let a = [0; 5];
@@ -833,7 +829,7 @@ impl<T: ?Sized> NonNull<T> {
833829
/// *Incorrect* usage:
834830
///
835831
/// ```rust,no_run
836-
/// #![feature(non_null_convenience, strict_provenance)]
832+
/// #![feature(strict_provenance)]
837833
/// use std::ptr::NonNull;
838834
///
839835
/// let ptr1 = NonNull::new(Box::into_raw(Box::new(0u8))).unwrap();
@@ -845,14 +841,13 @@ impl<T: ?Sized> NonNull<T> {
845841
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
846842
/// // computing their offset is undefined behavior, even though
847843
/// // they point to the same address!
848-
/// unsafe {
849-
/// let zero = ptr2_other.offset_from(ptr2); // Undefined Behavior
850-
/// }
844+
///
845+
/// let zero = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior
851846
/// ```
852-
#[unstable(feature = "non_null_convenience", issue = "117691")]
853-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
854847
#[inline]
855848
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
849+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
850+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
856851
pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize
857852
where
858853
T: Sized,
@@ -870,10 +865,10 @@ impl<T: ?Sized> NonNull<T> {
870865
///
871866
/// For non-`Sized` pointees this operation considers only the data pointers,
872867
/// ignoring the metadata.
873-
#[unstable(feature = "non_null_convenience", issue = "117691")]
874-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
875868
#[inline(always)]
876869
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
870+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
871+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
877872
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize {
878873
// SAFETY: the caller must uphold the safety contract for `byte_offset_from`.
879874
unsafe { self.pointer.byte_offset_from(origin.pointer) }
@@ -897,7 +892,7 @@ impl<T: ?Sized> NonNull<T> {
897892
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
898893
/// that their safety preconditions are met:
899894
/// ```rust
900-
/// # #![feature(non_null_convenience)]
895+
/// # #![feature(ptr_sub_ptr)]
901896
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool {
902897
/// ptr.sub_ptr(origin) == count
903898
/// # &&
@@ -926,7 +921,7 @@ impl<T: ?Sized> NonNull<T> {
926921
/// # Examples
927922
///
928923
/// ```
929-
/// #![feature(non_null_convenience)]
924+
/// #![feature(ptr_sub_ptr)]
930925
/// use std::ptr::NonNull;
931926
///
932927
/// let a = [0; 5];
@@ -942,12 +937,10 @@ impl<T: ?Sized> NonNull<T> {
942937
/// // This would be incorrect, as the pointers are not correctly ordered:
943938
/// // ptr1.sub_ptr(ptr2)
944939
/// ```
945-
#[unstable(feature = "non_null_convenience", issue = "117691")]
946-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
947-
// #[unstable(feature = "ptr_sub_ptr", issue = "95892")]
948-
// #[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
949940
#[inline]
950941
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
942+
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
943+
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
951944
pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize
952945
where
953946
T: Sized,
@@ -962,10 +955,10 @@ impl<T: ?Sized> NonNull<T> {
962955
/// See [`ptr::read`] for safety concerns and examples.
963956
///
964957
/// [`ptr::read`]: crate::ptr::read()
965-
#[unstable(feature = "non_null_convenience", issue = "117691")]
966-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
967958
#[inline]
968959
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
960+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
961+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
969962
pub const unsafe fn read(self) -> T
970963
where
971964
T: Sized,
@@ -984,9 +977,9 @@ impl<T: ?Sized> NonNull<T> {
984977
/// See [`ptr::read_volatile`] for safety concerns and examples.
985978
///
986979
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
987-
#[unstable(feature = "non_null_convenience", issue = "117691")]
988980
#[inline]
989981
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
982+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
990983
pub unsafe fn read_volatile(self) -> T
991984
where
992985
T: Sized,
@@ -1003,10 +996,10 @@ impl<T: ?Sized> NonNull<T> {
1003996
/// See [`ptr::read_unaligned`] for safety concerns and examples.
1004997
///
1005998
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
1006-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1007-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1008999
#[inline]
10091000
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1001+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1002+
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
10101003
pub const unsafe fn read_unaligned(self) -> T
10111004
where
10121005
T: Sized,
@@ -1023,10 +1016,10 @@ impl<T: ?Sized> NonNull<T> {
10231016
/// See [`ptr::copy`] for safety concerns and examples.
10241017
///
10251018
/// [`ptr::copy`]: crate::ptr::copy()
1026-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1027-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
10281019
#[inline(always)]
10291020
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1021+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1022+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
10301023
pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize)
10311024
where
10321025
T: Sized,
@@ -1043,10 +1036,10 @@ impl<T: ?Sized> NonNull<T> {
10431036
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
10441037
///
10451038
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
1046-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1047-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
10481039
#[inline(always)]
10491040
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1041+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1042+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
10501043
pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize)
10511044
where
10521045
T: Sized,
@@ -1063,10 +1056,10 @@ impl<T: ?Sized> NonNull<T> {
10631056
/// See [`ptr::copy`] for safety concerns and examples.
10641057
///
10651058
/// [`ptr::copy`]: crate::ptr::copy()
1066-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1067-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
10681059
#[inline(always)]
10691060
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1061+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1062+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
10701063
pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize)
10711064
where
10721065
T: Sized,
@@ -1083,10 +1076,10 @@ impl<T: ?Sized> NonNull<T> {
10831076
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
10841077
///
10851078
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
1086-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1087-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
10881079
#[inline(always)]
10891080
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1081+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1082+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
10901083
pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize)
10911084
where
10921085
T: Sized,
@@ -1100,8 +1093,8 @@ impl<T: ?Sized> NonNull<T> {
11001093
/// See [`ptr::drop_in_place`] for safety concerns and examples.
11011094
///
11021095
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
1103-
#[unstable(feature = "non_null_convenience", issue = "117691")]
11041096
#[inline(always)]
1097+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
11051098
pub unsafe fn drop_in_place(self) {
11061099
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
11071100
unsafe { ptr::drop_in_place(self.as_ptr()) }
@@ -1113,11 +1106,10 @@ impl<T: ?Sized> NonNull<T> {
11131106
/// See [`ptr::write`] for safety concerns and examples.
11141107
///
11151108
/// [`ptr::write`]: crate::ptr::write()
1116-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1117-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1118-
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11191109
#[inline(always)]
11201110
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1111+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1112+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11211113
pub const unsafe fn write(self, val: T)
11221114
where
11231115
T: Sized,
@@ -1132,12 +1124,11 @@ impl<T: ?Sized> NonNull<T> {
11321124
/// See [`ptr::write_bytes`] for safety concerns and examples.
11331125
///
11341126
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
1135-
#[doc(alias = "memset")]
1136-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1137-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1138-
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11391127
#[inline(always)]
1128+
#[doc(alias = "memset")]
11401129
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1130+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1131+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11411132
pub const unsafe fn write_bytes(self, val: u8, count: usize)
11421133
where
11431134
T: Sized,
@@ -1156,9 +1147,9 @@ impl<T: ?Sized> NonNull<T> {
11561147
/// See [`ptr::write_volatile`] for safety concerns and examples.
11571148
///
11581149
/// [`ptr::write_volatile`]: crate::ptr::write_volatile()
1159-
#[unstable(feature = "non_null_convenience", issue = "117691")]
11601150
#[inline(always)]
11611151
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1152+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
11621153
pub unsafe fn write_volatile(self, val: T)
11631154
where
11641155
T: Sized,
@@ -1175,11 +1166,10 @@ impl<T: ?Sized> NonNull<T> {
11751166
/// See [`ptr::write_unaligned`] for safety concerns and examples.
11761167
///
11771168
/// [`ptr::write_unaligned`]: crate::ptr::write_unaligned()
1178-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1179-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1180-
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11811169
#[inline(always)]
11821170
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1171+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1172+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
11831173
pub const unsafe fn write_unaligned(self, val: T)
11841174
where
11851175
T: Sized,
@@ -1194,8 +1184,8 @@ impl<T: ?Sized> NonNull<T> {
11941184
/// See [`ptr::replace`] for safety concerns and examples.
11951185
///
11961186
/// [`ptr::replace`]: crate::ptr::replace()
1197-
#[unstable(feature = "non_null_convenience", issue = "117691")]
11981187
#[inline(always)]
1188+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
11991189
pub unsafe fn replace(self, src: T) -> T
12001190
where
12011191
T: Sized,
@@ -1211,10 +1201,9 @@ impl<T: ?Sized> NonNull<T> {
12111201
/// See [`ptr::swap`] for safety concerns and examples.
12121202
///
12131203
/// [`ptr::swap`]: crate::ptr::swap()
1214-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1215-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1216-
//#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
12171204
#[inline(always)]
1205+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1206+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
12181207
pub const unsafe fn swap(self, with: NonNull<T>)
12191208
where
12201209
T: Sized,
@@ -1246,7 +1235,6 @@ impl<T: ?Sized> NonNull<T> {
12461235
/// Accessing adjacent `u8` as `u16`
12471236
///
12481237
/// ```
1249-
/// #![feature(non_null_convenience)]
12501238
/// use std::mem::align_of;
12511239
/// use std::ptr::NonNull;
12521240
///
@@ -1264,11 +1252,10 @@ impl<T: ?Sized> NonNull<T> {
12641252
/// }
12651253
/// # }
12661254
/// ```
1267-
#[unstable(feature = "non_null_convenience", issue = "117691")]
1268-
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
1269-
//#[rustc_const_unstable(feature = "const_align_offset", issue = "90962")]
1270-
#[must_use]
12711255
#[inline]
1256+
#[must_use]
1257+
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
1258+
#[rustc_const_unstable(feature = "const_align_offset", issue = "90962")]
12721259
pub const fn align_offset(self, align: usize) -> usize
12731260
where
12741261
T: Sized,
@@ -1312,10 +1299,9 @@ impl<T: ?Sized> NonNull<T> {
13121299
/// underlying allocation.
13131300
///
13141301
/// ```
1315-
/// #![feature(const_pointer_is_aligned)]
1316-
/// #![feature(non_null_convenience)]
1317-
/// #![feature(const_option)]
13181302
/// #![feature(const_nonnull_new)]
1303+
/// #![feature(const_option)]
1304+
/// #![feature(const_pointer_is_aligned)]
13191305
/// use std::ptr::NonNull;
13201306
///
13211307
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1390,10 +1376,10 @@ impl<T: ?Sized> NonNull<T> {
13901376
/// ```
13911377
///
13921378
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1379+
#[inline]
1380+
#[must_use]
13931381
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
13941382
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
1395-
#[must_use]
1396-
#[inline]
13971383
pub const fn is_aligned(self) -> bool
13981384
where
13991385
T: Sized,
@@ -1505,10 +1491,10 @@ impl<T: ?Sized> NonNull<T> {
15051491
/// ```
15061492
///
15071493
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1494+
#[inline]
1495+
#[must_use]
15081496
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
15091497
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
1510-
#[must_use]
1511-
#[inline]
15121498
pub const fn is_aligned_to(self, align: usize) -> bool {
15131499
self.pointer.is_aligned_to(align)
15141500
}

0 commit comments

Comments
 (0)
Please sign in to comment.