diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index c20ac042516af..7f82aeb0cbc63 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -10,6 +10,7 @@ #![allow(internal_features)] #![allow(rustc::default_hash_types)] #![allow(rustc::potential_query_instability)] +#![cfg_attr(bootstrap, feature(ptr_alignment_type))] #![cfg_attr(bootstrap, feature(unwrap_infallible))] #![cfg_attr(test, feature(test))] #![deny(unsafe_op_in_unsafe_fn)] @@ -28,7 +29,6 @@ #![feature(nonzero_internals)] #![feature(pattern_type_macro)] #![feature(pattern_types)] -#![feature(ptr_alignment_type)] #![feature(rustc_attrs)] #![feature(sized_hierarchy)] #![feature(thread_id_value)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 695eca6225858..0b404cf43c80d 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -28,6 +28,7 @@ #![allow(internal_features)] #![allow(rustc::direct_use_of_rustc_type_ir)] #![cfg_attr(bootstrap, feature(debug_closure_helpers))] +#![cfg_attr(bootstrap, feature(ptr_alignment_type))] #![cfg_attr(doc, feature(intra_doc_pointers))] #![feature(allocator_ext)] #![feature(associated_type_defaults)] @@ -45,7 +46,6 @@ #![feature(min_specialization)] #![feature(negative_impls)] #![feature(option_into_flat_iter)] -#![feature(ptr_alignment_type)] #![feature(range_bounds_is_empty)] #![feature(rustc_attrs)] #![feature(sized_hierarchy)] diff --git a/library/core/src/mem/alignment.rs b/library/core/src/mem/alignment.rs index 4b0d7e96a38d1..77e425aee5c33 100644 --- a/library/core/src/mem/alignment.rs +++ b/library/core/src/mem/alignment.rs @@ -1,6 +1,5 @@ #![allow(clippy::enum_clike_unportable_variant)] -use crate::marker::MetaSized; use crate::num::NonZero; use crate::ub_checks::assert_unsafe_precondition; use crate::{cmp, fmt, hash, mem, num}; @@ -10,7 +9,7 @@ use crate::{cmp, fmt, hash, mem, num}; /// /// Note that particularly large alignments, while representable in this type, /// are likely not to be supported by actual allocators and linkers. -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[derive(Copy)] #[derive_const(Clone, PartialEq, Eq)] #[repr(transparent)] @@ -37,19 +36,19 @@ impl Alignment { /// # Examples /// /// ``` - /// #![feature(ptr_alignment_type)] /// use std::mem::Alignment; /// /// assert_eq!(Alignment::MIN.as_usize(), 1); /// ``` - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] pub const MIN: Self = Self::new(1).unwrap(); /// Returns the alignment for a type. /// /// This provides the same numerical value as [`align_of`], /// but in an `Alignment` instead of a `usize`. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[inline] #[must_use] pub const fn of() -> Self { @@ -71,7 +70,6 @@ impl Alignment { /// # Examples /// /// ``` - /// #![feature(ptr_alignment_type)] /// use std::mem::Alignment; /// /// assert_eq!(Alignment::of_val(&5i32).as_usize(), 4); @@ -84,7 +82,6 @@ impl Alignment { /// `Alignment::of_val()` can be used to learn those alignments: /// /// ``` - /// #![feature(ptr_alignment_type)] /// use std::mem::Alignment; /// /// let a: &dyn ToString = &1234u16; @@ -97,8 +94,9 @@ impl Alignment { /// [type-layout]: ../../reference/type-layout.html#r-layout.primitive #[inline] #[must_use] - #[unstable(feature = "ptr_alignment_type", issue = "102070")] - pub const fn of_val(val: &T) -> Self { + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + pub const fn of_val(val: &T) -> Self { let align = mem::align_of_val(val); // SAFETY: `align_of_val` returns valid alignment unsafe { Alignment::new_unchecked(align) } @@ -141,7 +139,6 @@ impl Alignment { /// # Examples /// /// ``` - /// #![feature(ptr_alignment_type)] /// use std::mem::Alignment; /// /// assert_eq!(unsafe { Alignment::of_val_raw(&5i32) }.as_usize(), 4); @@ -153,8 +150,9 @@ impl Alignment { /// [type-layout]: ../../reference/type-layout.html#r-layout.primitive #[inline] #[must_use] - #[unstable(feature = "ptr_alignment_type", issue = "102070")] - pub const unsafe fn of_val_raw(val: *const T) -> Self { + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + pub const unsafe fn of_val_raw(val: *const T) -> Self { // SAFETY: precondition propagated to the caller let align = unsafe { mem::align_of_val_raw(val) }; // SAFETY: `align_of_val_raw` returns valid alignment @@ -165,7 +163,8 @@ impl Alignment { /// not a power of two. /// /// Note that `0` is not a power of two, nor a valid alignment. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn new(align: usize) -> Option { if align.is_power_of_two() { @@ -184,7 +183,8 @@ impl Alignment { /// /// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`. /// It must *not* be zero. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[inline] #[track_caller] pub const unsafe fn new_unchecked(align: usize) -> Self { @@ -200,7 +200,8 @@ impl Alignment { } /// Returns the alignment as a [`usize`]. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn as_usize(self) -> usize { // Going through `as_nonzero_usize` helps this be more clearly the inverse of @@ -210,19 +211,8 @@ impl Alignment { } /// Returns the alignment as a [NonZero]<[usize]>. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] - #[deprecated( - since = "1.96.0", - note = "renamed to `as_nonzero_usize`", - suggestion = "as_nonzero_usize" - )] - #[inline] - pub const fn as_nonzero(self) -> NonZero { - self.as_nonzero_usize() - } - - /// Returns the alignment as a [NonZero]<[usize]>. - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn as_nonzero_usize(self) -> NonZero { // This transmutes directly to avoid the UbCheck in `NonZero::new_unchecked` @@ -242,7 +232,7 @@ impl Alignment { /// /// ``` /// #![feature(ptr_alignment_type)] - /// use std::ptr::Alignment; + /// use std::mem::Alignment; /// /// assert_eq!(Alignment::of::().log2(), 0); /// assert_eq!(Alignment::new(1024).unwrap().log2(), 10); @@ -261,7 +251,6 @@ impl Alignment { /// /// ``` /// #![feature(ptr_mask)] - /// #![feature(ptr_alignment_type)] /// use std::mem::Alignment; /// use std::ptr::NonNull; /// @@ -277,7 +266,7 @@ impl Alignment { /// assert_eq!(four.mask(Alignment::of::().mask()), four); /// assert_ne!(one.mask(Alignment::of::().mask()), one); /// ``` - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[unstable(feature = "ptr_mask", issue = "98290")] #[inline] pub const fn mask(self) -> usize { // SAFETY: The alignment is always nonzero, and therefore decrementing won't overflow. @@ -290,14 +279,14 @@ impl Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] impl fmt::Debug for Alignment { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?} (1 << {:?})", self.as_nonzero_usize(), self.log2()) } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl TryFrom> for Alignment { type Error = num::TryFromIntError; @@ -308,7 +297,7 @@ const impl TryFrom> for Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl TryFrom for Alignment { type Error = num::TryFromIntError; @@ -319,7 +308,7 @@ const impl TryFrom for Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl From for NonZero { #[inline] @@ -328,7 +317,7 @@ const impl From for NonZero { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl From for usize { #[inline] @@ -337,7 +326,7 @@ const impl From for usize { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] const impl cmp::Ord for Alignment { #[inline] @@ -346,7 +335,7 @@ const impl cmp::Ord for Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] const impl cmp::PartialOrd for Alignment { #[inline] @@ -355,7 +344,7 @@ const impl cmp::PartialOrd for Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] impl hash::Hash for Alignment { #[inline] fn hash(&self, state: &mut H) { @@ -364,7 +353,7 @@ impl hash::Hash for Alignment { } /// Returns [`Alignment::MIN`], which is valid for any type. -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_default", issue = "143894")] const impl Default for Alignment { fn default() -> Alignment { diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index b38557779092c..109908a002507 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -39,7 +39,7 @@ use crate::ub_checks::assert_unsafe_precondition; use crate::{clone, cmp, fmt, hash, intrinsics, ptr}; mod alignment; -#[unstable(feature = "ptr_alignment_type", issue = "102070")] +#[stable(feature = "alignment_type", since = "CURRENT_RUSTC_VERSION")] pub use alignment::Alignment; mod manually_drop; @@ -1477,7 +1477,7 @@ pub trait SizedTypeProperties: Sized { const ALIGN: usize = intrinsics::align_of::(); #[doc(hidden)] - #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[unstable(feature = "sized_type_properties", issue = "none")] const ALIGNMENT: Alignment = { // This can't panic since type alignment is always a power of two. Alignment::new(Self::ALIGN).unwrap() diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index be3dc5e013b32..f83a4b852d04d 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -434,11 +434,6 @@ use crate::num::NonZero; use crate::ops::FnPtr; use crate::{fmt, hash, intrinsics, ub_checks}; -#[unstable(feature = "ptr_alignment_type", issue = "102070")] -#[deprecated(since = "1.96.0", note = "moved from `ptr` to `mem`")] -/// Deprecated re-export of [mem::Alignment]. -pub type Alignment = mem::Alignment; - mod metadata; #[unstable(feature = "ptr_metadata", issue = "81513")] pub use metadata::{DynMetadata, Pointee, Thin, from_raw_parts, from_raw_parts_mut, metadata}; diff --git a/src/tools/miri/tests/fail/alloc/too_large.rs b/src/tools/miri/tests/fail/alloc/too_large.rs index 899fc30d9a576..b3ab24eb6889c 100644 --- a/src/tools/miri/tests/fail/alloc/too_large.rs +++ b/src/tools/miri/tests/fail/alloc/too_large.rs @@ -1,5 +1,4 @@ #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] extern "Rust" { #[rustc_std_internal_symbol] @@ -9,6 +8,6 @@ extern "Rust" { fn main() { let bytes = isize::MAX as usize + 1; unsafe { - __rust_alloc(bytes, 1usize.try_into().unwrap()); //~ERROR: larger than half the address space + __rust_alloc(bytes, core::mem::Alignment::MIN); //~ERROR: larger than half the address space } } diff --git a/src/tools/miri/tests/fail/alloc/too_large.stderr b/src/tools/miri/tests/fail/alloc/too_large.stderr index 86c8aac242ac6..2af43f2a06883 100644 --- a/src/tools/miri/tests/fail/alloc/too_large.stderr +++ b/src/tools/miri/tests/fail/alloc/too_large.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: creating an allocation larger than half the address space --> tests/fail/alloc/too_large.rs:LL:CC | -LL | __rust_alloc(bytes, 1usize.try_into().unwrap()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here +LL | __rust_alloc(bytes, core::mem::Alignment::MIN); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.rs b/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.rs index a60156982caa4..dd2941bde4b3e 100644 --- a/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.rs +++ b/src/tools/miri/tests/fail/alloc/unsupported_big_alignment.rs @@ -3,7 +3,6 @@ // https://github.com/rust-lang/miri/issues/3687 #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] extern "Rust" { #[rustc_std_internal_symbol] diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs index 0b16d0616ba95..d924348e15905 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs @@ -2,7 +2,6 @@ //@compile-flags: -Zmiri-deterministic-concurrency -Zmiri-disable-stacked-borrows #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] use std::thread::spawn; @@ -34,7 +33,7 @@ fn main() { //~^ ERROR: Data race detected between (1) non-atomic read on thread `unnamed-1` and (2) deallocation on thread `unnamed-2` ptr.0 as *mut _, std::mem::size_of::(), - std::mem::align_of::().try_into().unwrap(), + std::mem::Alignment::of::(), ); }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr index a9353baa1beaa..41cba16a486e2 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr @@ -5,7 +5,7 @@ LL | / ... __rust_dealloc( LL | | ... LL | | ... ptr.0 as *mut _, LL | | ... std::mem::size_of::(), -LL | | ... std::mem::align_of::().try_into().unwrap(), +LL | | ... std::mem::Alignment::of::(), LL | | ... ); | |_______^ (2) just happened here | diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs index 566c729c912bc..c6a5522284efc 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs @@ -2,7 +2,6 @@ //@compile-flags: -Zmiri-deterministic-concurrency -Zmiri-disable-stacked-borrows #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] use std::thread::spawn; @@ -28,7 +27,7 @@ fn main() { __rust_dealloc( ptr.0 as *mut _, std::mem::size_of::(), - std::mem::align_of::().try_into().unwrap(), + std::mem::Alignment::of::(), ) }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.stderr b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.stderr index 2452a5587da6a..6525d7ee104ad 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.stderr @@ -17,7 +17,7 @@ help: ALLOC was deallocated here: LL | / __rust_dealloc( LL | | ptr.0 as *mut _, LL | | std::mem::size_of::(), -LL | | std::mem::align_of::().try_into().unwrap(), +LL | | std::mem::Alignment::of::(), LL | | ) | |_____________^ = note: this is on thread `unnamed-ID` diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs index 7fa769e88583f..44b557fee3f58 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs @@ -2,7 +2,6 @@ //@compile-flags: -Zmiri-deterministic-concurrency -Zmiri-disable-stacked-borrows #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] use std::thread::spawn; @@ -33,7 +32,7 @@ fn main() { //~^ ERROR: Data race detected between (1) non-atomic write on thread `unnamed-1` and (2) deallocation on thread `unnamed-2` ptr.0 as *mut _, std::mem::size_of::(), - std::mem::align_of::().try_into().unwrap(), + std::mem::Alignment::of::(), ); }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr index 3dbc3f3851391..ff10c48cd8c77 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr @@ -5,7 +5,7 @@ LL | / ... __rust_dealloc( LL | | ... LL | | ... ptr.0 as *mut _, LL | | ... std::mem::size_of::(), -LL | | ... std::mem::align_of::().try_into().unwrap(), +LL | | ... std::mem::Alignment::of::(), LL | | ... ); | |_______^ (2) just happened here | diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs index da452b00244bf..e23d15a794d54 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs @@ -2,7 +2,6 @@ //@compile-flags: -Zmiri-deterministic-concurrency -Zmiri-disable-stacked-borrows #![feature(rustc_attrs)] -#![feature(ptr_alignment_type)] use std::thread::spawn; @@ -27,7 +26,7 @@ fn main() { __rust_dealloc( ptr.0 as *mut _, std::mem::size_of::(), - std::mem::align_of::().try_into().unwrap(), + std::mem::Alignment::of::(), ); }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.stderr b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.stderr index dc0f8a30a0f6b..800dd3ffa7e2f 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.stderr @@ -17,7 +17,7 @@ help: ALLOC was deallocated here: LL | / __rust_dealloc( LL | | ptr.0 as *mut _, LL | | std::mem::size_of::(), -LL | | std::mem::align_of::().try_into().unwrap(), +LL | | std::mem::Alignment::of::(), LL | | ); | |_____________^ = note: this is on thread `unnamed-ID` diff --git a/tests/ui/precondition-checks/alignment.rs b/tests/ui/precondition-checks/alignment.rs index 3f0eae47a157a..3903b7b7b040b 100644 --- a/tests/ui/precondition-checks/alignment.rs +++ b/tests/ui/precondition-checks/alignment.rs @@ -2,8 +2,6 @@ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes //@ error-pattern: unsafe precondition(s) violated: Alignment::new_unchecked requires -#![feature(ptr_alignment_type)] - fn main() { unsafe { std::mem::Alignment::new_unchecked(0); diff --git a/tests/ui/traits/const-traits/const-traits-core.rs b/tests/ui/traits/const-traits/const-traits-core.rs index ed244c230006a..d4fcc1c10a792 100644 --- a/tests/ui/traits/const-traits/const-traits-core.rs +++ b/tests/ui/traits/const-traits/const-traits-core.rs @@ -3,7 +3,6 @@ const_clone, const_default, const_trait_impl, - ptr_alignment_type, ascii_char, f16, f128,