11#![ allow( clippy:: enum_clike_unportable_variant) ]
22
3- use crate :: marker:: MetaSized ;
43use crate :: num:: NonZero ;
54use crate :: ub_checks:: assert_unsafe_precondition;
65use crate :: { cmp, fmt, hash, mem, num} ;
@@ -10,7 +9,7 @@ use crate::{cmp, fmt, hash, mem, num};
109///
1110/// Note that particularly large alignments, while representable in this type,
1211/// are likely not to be supported by actual allocators and linkers.
13- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
12+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
1413#[ derive( Copy ) ]
1514#[ derive_const( Clone , PartialEq , Eq ) ]
1615#[ repr( transparent) ]
@@ -37,19 +36,19 @@ impl Alignment {
3736 /// # Examples
3837 ///
3938 /// ```
40- /// #![feature(ptr_alignment_type)]
4139 /// use std::mem::Alignment;
4240 ///
4341 /// assert_eq!(Alignment::MIN.as_usize(), 1);
4442 /// ```
45- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
43+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
4644 pub const MIN : Self = Self :: new ( 1 ) . unwrap ( ) ;
4745
4846 /// Returns the alignment for a type.
4947 ///
5048 /// This provides the same numerical value as [`align_of`],
5149 /// but in an `Alignment` instead of a `usize`.
52- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
50+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
51+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
5352 #[ inline]
5453 #[ must_use]
5554 pub const fn of < T > ( ) -> Self {
@@ -71,7 +70,6 @@ impl Alignment {
7170 /// # Examples
7271 ///
7372 /// ```
74- /// #![feature(ptr_alignment_type)]
7573 /// use std::mem::Alignment;
7674 ///
7775 /// assert_eq!(Alignment::of_val(&5i32).as_usize(), 4);
@@ -84,7 +82,6 @@ impl Alignment {
8482 /// `Alignment::of_val()` can be used to learn those alignments:
8583 ///
8684 /// ```
87- /// #![feature(ptr_alignment_type)]
8885 /// use std::mem::Alignment;
8986 ///
9087 /// let a: &dyn ToString = &1234u16;
@@ -97,8 +94,9 @@ impl Alignment {
9794 /// [type-layout]: ../../reference/type-layout.html#r-layout.primitive
9895 #[ inline]
9996 #[ must_use]
100- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
101- pub const fn of_val < T : MetaSized > ( val : & T ) -> Self {
97+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
98+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
99+ pub const fn of_val < T : ?Sized > ( val : & T ) -> Self {
102100 let align = mem:: align_of_val ( val) ;
103101 // SAFETY: `align_of_val` returns valid alignment
104102 unsafe { Alignment :: new_unchecked ( align) }
@@ -141,7 +139,6 @@ impl Alignment {
141139 /// # Examples
142140 ///
143141 /// ```
144- /// #![feature(ptr_alignment_type)]
145142 /// use std::mem::Alignment;
146143 ///
147144 /// assert_eq!(unsafe { Alignment::of_val_raw(&5i32) }.as_usize(), 4);
@@ -153,8 +150,9 @@ impl Alignment {
153150 /// [type-layout]: ../../reference/type-layout.html#r-layout.primitive
154151 #[ inline]
155152 #[ must_use]
156- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
157- pub const unsafe fn of_val_raw < T : MetaSized > ( val : * const T ) -> Self {
153+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
154+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
155+ pub const unsafe fn of_val_raw < T : ?Sized > ( val : * const T ) -> Self {
158156 // SAFETY: precondition propagated to the caller
159157 let align = unsafe { mem:: align_of_val_raw ( val) } ;
160158 // SAFETY: `align_of_val_raw` returns valid alignment
@@ -165,7 +163,8 @@ impl Alignment {
165163 /// not a power of two.
166164 ///
167165 /// Note that `0` is not a power of two, nor a valid alignment.
168- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
166+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
167+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
169168 #[ inline]
170169 pub const fn new ( align : usize ) -> Option < Self > {
171170 if align. is_power_of_two ( ) {
@@ -184,7 +183,8 @@ impl Alignment {
184183 ///
185184 /// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`.
186185 /// It must *not* be zero.
187- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
186+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
187+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
188188 #[ inline]
189189 #[ track_caller]
190190 pub const unsafe fn new_unchecked ( align : usize ) -> Self {
@@ -200,7 +200,8 @@ impl Alignment {
200200 }
201201
202202 /// Returns the alignment as a [`usize`].
203- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
203+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
204+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
204205 #[ inline]
205206 pub const fn as_usize ( self ) -> usize {
206207 // Going through `as_nonzero_usize` helps this be more clearly the inverse of
@@ -210,19 +211,8 @@ impl Alignment {
210211 }
211212
212213 /// Returns the alignment as a <code>[NonZero]<[usize]></code>.
213- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
214- #[ deprecated(
215- since = "1.96.0" ,
216- note = "renamed to `as_nonzero_usize`" ,
217- suggestion = "as_nonzero_usize"
218- ) ]
219- #[ inline]
220- pub const fn as_nonzero ( self ) -> NonZero < usize > {
221- self . as_nonzero_usize ( )
222- }
223-
224- /// Returns the alignment as a <code>[NonZero]<[usize]></code>.
225- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
214+ #[ stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
215+ #[ rustc_const_stable( feature = "alignment_type" , since = "CURRENT_RUSTC_VERSION" ) ]
226216 #[ inline]
227217 pub const fn as_nonzero_usize ( self ) -> NonZero < usize > {
228218 // This transmutes directly to avoid the UbCheck in `NonZero::new_unchecked`
@@ -242,12 +232,12 @@ impl Alignment {
242232 ///
243233 /// ```
244234 /// #![feature(ptr_alignment_type)]
245- /// use std::ptr ::Alignment;
235+ /// use std::mem ::Alignment;
246236 ///
247237 /// assert_eq!(Alignment::of::<u8>().log2(), 0);
248238 /// assert_eq!(Alignment::new(1024).unwrap().log2(), 10);
249239 /// ```
250- #[ unstable( feature = "ptr_alignment_type" , issue = "102070 " ) ]
240+ #[ unstable( feature = "ptr_alignment_type" , issue = "165719 " ) ]
251241 #[ inline]
252242 pub const fn log2 ( self ) -> u32 {
253243 self . as_nonzero_usize ( ) . trailing_zeros ( )
@@ -260,8 +250,7 @@ impl Alignment {
260250 /// # Examples
261251 ///
262252 /// ```
263- /// #![feature(ptr_mask)]
264- /// #![feature(ptr_alignment_type)]
253+ /// #![feature(ptr_alignment_type, ptr_mask)]
265254 /// use std::mem::Alignment;
266255 /// use std::ptr::NonNull;
267256 ///
@@ -277,7 +266,8 @@ impl Alignment {
277266 /// assert_eq!(four.mask(Alignment::of::<Align4>().mask()), four);
278267 /// assert_ne!(one.mask(Alignment::of::<Align4>().mask()), one);
279268 /// ```
280- #[ unstable( feature = "ptr_alignment_type" , issue = "102070" ) ]
269+ #[ unstable( feature = "ptr_alignment_type" , issue = "165719" ) ]
270+ // Also #[unstable(feature = "ptr_mask", issue = "98290")]
281271 #[ inline]
282272 pub const fn mask ( self ) -> usize {
283273 // SAFETY: The alignment is always nonzero, and therefore decrementing won't overflow.
@@ -290,14 +280,14 @@ impl Alignment {
290280 }
291281}
292282
293- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
283+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
294284impl fmt:: Debug for Alignment {
295285 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
296286 write ! ( f, "{:?} (1 << {:?})" , self . as_nonzero_usize( ) , self . log2( ) )
297287 }
298288}
299289
300- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
290+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
301291#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
302292const impl TryFrom <NonZero <usize>> for Alignment {
303293 type Error = num:: TryFromIntError ;
@@ -308,7 +298,7 @@ const impl TryFrom<NonZero<usize>> for Alignment {
308298 }
309299}
310300
311- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
301+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
312302#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
313303const impl TryFrom <usize> for Alignment {
314304 type Error = num:: TryFromIntError ;
@@ -319,7 +309,7 @@ const impl TryFrom<usize> for Alignment {
319309 }
320310}
321311
322- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
312+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
323313#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
324314const impl From <Alignment > for NonZero <usize> {
325315 #[ inline]
@@ -328,7 +318,7 @@ const impl From<Alignment> for NonZero<usize> {
328318 }
329319}
330320
331- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
321+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
332322#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
333323const impl From <Alignment > for usize {
334324 #[ inline]
@@ -337,7 +327,7 @@ const impl From<Alignment> for usize {
337327 }
338328}
339329
340- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
330+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
341331#[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
342332const impl cmp:: Ord for Alignment {
343333 #[ inline]
@@ -346,7 +336,7 @@ const impl cmp::Ord for Alignment {
346336 }
347337}
348338
349- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
339+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
350340#[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
351341const impl cmp:: PartialOrd for Alignment {
352342 #[ inline]
@@ -355,7 +345,7 @@ const impl cmp::PartialOrd for Alignment {
355345 }
356346}
357347
358- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
348+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
359349impl hash:: Hash for Alignment {
360350 #[ inline]
361351 fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
@@ -364,7 +354,7 @@ impl hash::Hash for Alignment {
364354}
365355
366356/// Returns [`Alignment::MIN`], which is valid for any type.
367- #[ unstable ( feature = "ptr_alignment_type " , issue = "102070 " ) ]
357+ #[ stable ( feature = "alignment_type " , since = "CURRENT_RUSTC_VERSION " ) ]
368358#[ rustc_const_unstable( feature = "const_default" , issue = "143894" ) ]
369359const impl Default for Alignment {
370360 fn default( ) -> Alignment {
0 commit comments