From e3874d74ed883bb6aeb42fc59bd60456174f36af Mon Sep 17 00:00:00 2001 From: Aria Beingessner Date: Sun, 3 Mar 2024 14:44:15 -0500 Subject: [PATCH] stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate This is an alternative to #121920 --- .../0001-core-Disable-portable-simd-test.patch | 4 ++-- library/alloc/src/lib.rs | 1 - library/core/src/ptr/const_ptr.rs | 17 ++++++----------- library/core/src/ptr/mut_ptr.rs | 17 ++++++----------- library/core/src/ptr/non_null.rs | 16 ++++++---------- library/core/src/sync/atomic.rs | 6 ++---- library/core/tests/lib.rs | 2 +- library/std/src/lib.rs | 1 - .../miri/tests/pass-dep/shims/posix_memalign.rs | 2 +- tests/ui/mir/alignment/packed.rs | 2 +- tests/ui/structs-enums/type-sizes.rs | 2 +- 11 files changed, 26 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch b/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch index 914ae986b50e7..36d0789d2a23b 100644 --- a/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch +++ b/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch @@ -14,7 +14,7 @@ index d0a119c..76fdece 100644 @@ -89,7 +89,6 @@ #![feature(never_type)] #![feature(unwrap_infallible)] - #![feature(pointer_is_aligned)] + #![feature(pointer_is_aligned_to)] -#![feature(portable_simd)] #![feature(ptr_metadata)] #![feature(lazy_cell)] @@ -27,6 +27,6 @@ index d0a119c..76fdece 100644 mod slice; mod str; mod str_lossy; --- +-- 2.42.1 diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 28695ade5bf55..07df19f652678 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -195,7 +195,6 @@ #![feature(multiple_supertrait_upcastable)] #![feature(negative_impls)] #![feature(never_type)] -#![feature(pointer_is_aligned)] #![feature(rustc_allow_const_fn_unstable)] #![feature(rustc_attrs)] #![feature(slice_internals)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 85a56d37ab75c..0f1bbf59afb28 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1387,8 +1387,6 @@ impl *const T { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] - /// /// // On some platforms, the alignment of i32 is less than 4. /// #[repr(align(4))] /// struct AlignedI32(i32); @@ -1411,7 +1409,6 @@ impl *const T { /// underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1437,7 +1434,6 @@ impl *const T { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1463,7 +1459,6 @@ impl *const T { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1487,7 +1482,7 @@ impl *const T { /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned(self) -> bool where @@ -1508,7 +1503,7 @@ impl *const T { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// /// // On some platforms, the alignment of i32 is less than 4. /// #[repr(align(4))] @@ -1537,7 +1532,7 @@ impl *const T { /// cannot be stricter aligned than the reference's underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1562,7 +1557,7 @@ impl *const T { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1586,7 +1581,7 @@ impl *const T { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// const _: () = { @@ -1602,7 +1597,7 @@ impl *const T { /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 28ba26f5c16c4..01202a4f8bbe6 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1656,8 +1656,6 @@ impl *mut T { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] - /// /// // On some platforms, the alignment of i32 is less than 4. /// #[repr(align(4))] /// struct AlignedI32(i32); @@ -1680,7 +1678,6 @@ impl *mut T { /// underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// #![feature(const_mut_refs)] /// @@ -1707,7 +1704,6 @@ impl *mut T { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1734,7 +1730,6 @@ impl *mut T { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1758,7 +1753,7 @@ impl *mut T { /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned(self) -> bool where @@ -1779,7 +1774,7 @@ impl *mut T { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// /// // On some platforms, the alignment of i32 is less than 4. /// #[repr(align(4))] @@ -1808,7 +1803,7 @@ impl *mut T { /// cannot be stricter aligned than the reference's underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// #![feature(const_mut_refs)] /// @@ -1834,7 +1829,7 @@ impl *mut T { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1859,7 +1854,7 @@ impl *mut T { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// const _: () = { @@ -1875,7 +1870,7 @@ impl *mut T { /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] pub const fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index acb8c552a6338..5338654a6c74f 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1289,7 +1289,6 @@ impl NonNull { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] /// use std::ptr::NonNull; /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1314,7 +1313,6 @@ impl NonNull { /// underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// #![feature(non_null_convenience)] /// #![feature(const_option)] @@ -1344,7 +1342,6 @@ impl NonNull { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of primitives is less than their size. @@ -1370,7 +1367,6 @@ impl NonNull { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] /// #![feature(const_pointer_is_aligned)] /// #![feature(const_option)] /// #![feature(const_nonnull_new)] @@ -1395,7 +1391,7 @@ impl NonNull { /// ``` /// /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] #[must_use] #[inline] @@ -1418,7 +1414,7 @@ impl NonNull { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// /// // On some platforms, the alignment of i32 is less than 4. /// #[repr(align(4))] @@ -1447,7 +1443,7 @@ impl NonNull { /// cannot be stricter aligned than the reference's underlying allocation. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1472,7 +1468,7 @@ impl NonNull { /// pointer is aligned, even if the compiletime pointer wasn't aligned. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// // On some platforms, the alignment of i32 is less than 4. @@ -1496,7 +1492,7 @@ impl NonNull { /// runtime and compiletime. /// /// ``` - /// #![feature(pointer_is_aligned)] + /// #![feature(pointer_is_aligned_to)] /// #![feature(const_pointer_is_aligned)] /// /// const _: () = { @@ -1510,7 +1506,7 @@ impl NonNull { /// ``` /// /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 - #[unstable(feature = "pointer_is_aligned", issue = "96284")] + #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] #[must_use] #[inline] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 45193c11e1d6b..4e3e3fc88ec73 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -418,14 +418,13 @@ impl AtomicBool { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] /// use std::sync::atomic::{self, AtomicBool}; /// use std::mem::align_of; /// /// // Get a pointer to an allocated value /// let ptr: *mut bool = Box::into_raw(Box::new(false)); /// - /// assert!(ptr.is_aligned_to(align_of::())); + /// assert!(ptr.cast::().is_aligned()); /// /// { /// // Create an atomic view of the allocated value @@ -1216,14 +1215,13 @@ impl AtomicPtr { /// # Examples /// /// ``` - /// #![feature(pointer_is_aligned)] /// use std::sync::atomic::{self, AtomicPtr}; /// use std::mem::align_of; /// /// // Get a pointer to an allocated value /// let ptr: *mut *mut u8 = Box::into_raw(Box::new(std::ptr::null_mut())); /// - /// assert!(ptr.is_aligned_to(align_of::>())); + /// assert!(ptr.cast::>.is_aligned()); /// /// { /// // Create an atomic view of the allocated value diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index fa0e9a979d060..1ac98ec8460dd 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -92,7 +92,7 @@ #![feature(const_waker)] #![feature(never_type)] #![feature(unwrap_infallible)] -#![feature(pointer_is_aligned)] +#![feature(pointer_is_aligned_to)] #![feature(portable_simd)] #![feature(ptr_metadata)] #![feature(lazy_cell)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 288cce3aa085e..54128da6d92fd 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -339,7 +339,6 @@ #![feature(panic_can_unwind)] #![feature(panic_info_message)] #![feature(panic_internals)] -#![feature(pointer_is_aligned)] #![feature(portable_simd)] #![feature(prelude_2024)] #![feature(ptr_as_uninit)] diff --git a/src/tools/miri/tests/pass-dep/shims/posix_memalign.rs b/src/tools/miri/tests/pass-dep/shims/posix_memalign.rs index 5cf62995fbee2..db66b21341641 100644 --- a/src/tools/miri/tests/pass-dep/shims/posix_memalign.rs +++ b/src/tools/miri/tests/pass-dep/shims/posix_memalign.rs @@ -1,6 +1,6 @@ //@ignore-target-windows: No libc on Windows -#![feature(pointer_is_aligned)] +#![feature(pointer_is_aligned_to)] #![feature(strict_provenance)] use core::ptr; diff --git a/tests/ui/mir/alignment/packed.rs b/tests/ui/mir/alignment/packed.rs index fe8ecc668b868..1a12425f11a96 100644 --- a/tests/ui/mir/alignment/packed.rs +++ b/tests/ui/mir/alignment/packed.rs @@ -1,7 +1,7 @@ //@ run-pass //@ compile-flags: -C debug-assertions -#![feature(strict_provenance, pointer_is_aligned)] +#![feature(strict_provenance)] #[repr(packed)] struct Misaligner { diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs index 66f663ce0776c..50491d5ef3eb6 100644 --- a/tests/ui/structs-enums/type-sizes.rs +++ b/tests/ui/structs-enums/type-sizes.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] #![feature(generic_nonzero)] #![feature(never_type)] -#![feature(pointer_is_aligned)] +#![feature(pointer_is_aligned_to)] #![feature(strict_provenance)] use std::mem::size_of;