Skip to content

Commit

Permalink
stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
Browse files Browse the repository at this point in the history
This is an alternative to #121920
  • Loading branch information
Gankra committed Mar 3, 2024
1 parent 279c9ba commit 5e70c8e
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -27,6 +27,6 @@ index d0a119c..76fdece 100644
mod slice;
mod str;
mod str_lossy;
--
--
2.42.1

1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#![feature(const_trait_impl)]
#![feature(const_str_from_utf8)]
#![feature(panic_update_hook)]
#![feature(pointer_is_aligned)]
#![feature(pointer_is_aligned_to)]
#![feature(slice_flatten)]
#![feature(thin_box)]
#![feature(strict_provenance)]
Expand Down
17 changes: 6 additions & 11 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,6 @@ impl<T: ?Sized> *const T {
/// # Examples
///
/// ```
/// #![feature(pointer_is_aligned)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
/// struct AlignedI32(i32);
Expand All @@ -1411,7 +1409,6 @@ impl<T: ?Sized> *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.
Expand All @@ -1437,7 +1434,6 @@ impl<T: ?Sized> *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.
Expand All @@ -1463,7 +1459,6 @@ impl<T: ?Sized> *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.
Expand All @@ -1487,7 +1482,7 @@ impl<T: ?Sized> *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
Expand All @@ -1508,7 +1503,7 @@ impl<T: ?Sized> *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))]
Expand Down Expand Up @@ -1537,7 +1532,7 @@ impl<T: ?Sized> *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.
Expand All @@ -1562,7 +1557,7 @@ impl<T: ?Sized> *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.
Expand All @@ -1586,7 +1581,7 @@ impl<T: ?Sized> *const T {
/// runtime and compiletime.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_is_aligned_to)]
/// #![feature(const_pointer_is_aligned)]
///
/// const _: () = {
Expand All @@ -1602,7 +1597,7 @@ impl<T: ?Sized> *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() {
Expand Down
17 changes: 6 additions & 11 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,8 +1656,6 @@ impl<T: ?Sized> *mut T {
/// # Examples
///
/// ```
/// #![feature(pointer_is_aligned)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
/// struct AlignedI32(i32);
Expand All @@ -1680,7 +1678,6 @@ impl<T: ?Sized> *mut T {
/// underlying allocation.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(const_pointer_is_aligned)]
/// #![feature(const_mut_refs)]
///
Expand All @@ -1707,7 +1704,6 @@ impl<T: ?Sized> *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.
Expand All @@ -1734,7 +1730,6 @@ impl<T: ?Sized> *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.
Expand All @@ -1758,7 +1753,7 @@ impl<T: ?Sized> *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
Expand All @@ -1779,7 +1774,7 @@ impl<T: ?Sized> *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))]
Expand Down Expand Up @@ -1808,7 +1803,7 @@ impl<T: ?Sized> *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)]
///
Expand All @@ -1834,7 +1829,7 @@ impl<T: ?Sized> *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.
Expand All @@ -1859,7 +1854,7 @@ impl<T: ?Sized> *mut T {
/// runtime and compiletime.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_is_aligned_to)]
/// #![feature(const_pointer_is_aligned)]
///
/// const _: () = {
Expand All @@ -1875,7 +1870,7 @@ impl<T: ?Sized> *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() {
Expand Down
16 changes: 6 additions & 10 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,6 @@ impl<T: ?Sized> NonNull<T> {
/// # Examples
///
/// ```
/// #![feature(pointer_is_aligned)]
/// use std::ptr::NonNull;
///
/// // On some platforms, the alignment of i32 is less than 4.
Expand All @@ -1314,7 +1313,6 @@ impl<T: ?Sized> NonNull<T> {
/// underlying allocation.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(const_pointer_is_aligned)]
/// #![feature(non_null_convenience)]
/// #![feature(const_option)]
Expand Down Expand Up @@ -1344,7 +1342,6 @@ impl<T: ?Sized> NonNull<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.
Expand All @@ -1370,7 +1367,6 @@ impl<T: ?Sized> NonNull<T> {
/// runtime and compiletime.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(const_pointer_is_aligned)]
/// #![feature(const_option)]
/// #![feature(const_nonnull_new)]
Expand All @@ -1395,7 +1391,7 @@ impl<T: ?Sized> NonNull<T> {
/// ```
///
/// [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]
Expand All @@ -1418,7 +1414,7 @@ impl<T: ?Sized> NonNull<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))]
Expand Down Expand Up @@ -1447,7 +1443,7 @@ impl<T: ?Sized> NonNull<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.
Expand All @@ -1472,7 +1468,7 @@ impl<T: ?Sized> NonNull<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.
Expand All @@ -1496,7 +1492,7 @@ impl<T: ?Sized> NonNull<T> {
/// runtime and compiletime.
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_is_aligned_to)]
/// #![feature(const_pointer_is_aligned)]
///
/// const _: () = {
Expand All @@ -1510,7 +1506,7 @@ impl<T: ?Sized> NonNull<T> {
/// ```
///
/// [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]
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,13 @@ impl AtomicBool {
/// # Examples
///
/// ```
/// #![feature(pointer_is_aligned)]
/// use std::sync::atomic::{self, AtomicBool};
/// use std::mem::align_of;

Check failure on line 422 in library/core/src/sync/atomic.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check

unused import: `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::<AtomicBool>()));
/// assert!(ptr.cast::<AtomicBool>().is_aligned());
///
/// {
/// // Create an atomic view of the allocated value
Expand Down Expand Up @@ -1216,14 +1215,13 @@ impl<T> AtomicPtr<T> {
/// # 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::<AtomicPtr<u8>>()));
/// assert!(ptr.cast::<AtomicPtr<u8>>.is_aligned());
///
/// {
/// // Create an atomic view of the allocated value
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/pass-dep/shims/posix_memalign.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mir/alignment/packed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-pass
//@ compile-flags: -C debug-assertions

#![feature(strict_provenance, pointer_is_aligned)]
#![feature(strict_provenance)]

#[repr(packed)]
struct Misaligner {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs-enums/type-sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5e70c8e

Please sign in to comment.