mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
This is an alternative to #121920
This commit is contained in:
parent
faae5f1ffe
commit
ea92faec49
@ -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
|
||||
|
||||
|
@ -198,7 +198,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)]
|
||||
|
@ -37,7 +37,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)]
|
||||
|
@ -1401,8 +1401,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);
|
||||
@ -1425,7 +1423,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.
|
||||
@ -1451,7 +1448,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.
|
||||
@ -1477,7 +1473,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.
|
||||
@ -1501,7 +1496,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
|
||||
@ -1522,7 +1517,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))]
|
||||
@ -1551,7 +1546,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.
|
||||
@ -1576,7 +1571,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.
|
||||
@ -1600,7 +1595,7 @@ impl<T: ?Sized> *const T {
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(pointer_is_aligned_to)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// const _: () = {
|
||||
@ -1616,7 +1611,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() {
|
||||
|
@ -1660,8 +1660,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);
|
||||
@ -1684,7 +1682,6 @@ impl<T: ?Sized> *mut T {
|
||||
/// underlying allocation.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
/// #![feature(const_mut_refs)]
|
||||
///
|
||||
@ -1711,7 +1708,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.
|
||||
@ -1738,7 +1734,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.
|
||||
@ -1762,7 +1757,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
|
||||
@ -1783,7 +1778,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))]
|
||||
@ -1812,7 +1807,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)]
|
||||
///
|
||||
@ -1838,7 +1833,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.
|
||||
@ -1863,7 +1858,7 @@ impl<T: ?Sized> *mut T {
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(pointer_is_aligned_to)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// const _: () = {
|
||||
@ -1879,7 +1874,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() {
|
||||
|
@ -1288,7 +1288,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.
|
||||
@ -1313,7 +1312,6 @@ impl<T: ?Sized> NonNull<T> {
|
||||
/// underlying allocation.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
/// #![feature(non_null_convenience)]
|
||||
/// #![feature(const_option)]
|
||||
@ -1343,7 +1341,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.
|
||||
@ -1369,7 +1366,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)]
|
||||
@ -1394,7 +1390,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]
|
||||
@ -1417,7 +1413,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))]
|
||||
@ -1446,7 +1442,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.
|
||||
@ -1471,7 +1467,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.
|
||||
@ -1495,7 +1491,7 @@ impl<T: ?Sized> NonNull<T> {
|
||||
/// runtime and compiletime.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
/// #![feature(pointer_is_aligned_to)]
|
||||
/// #![feature(const_pointer_is_aligned)]
|
||||
///
|
||||
/// const _: () = {
|
||||
@ -1509,7 +1505,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]
|
||||
|
@ -418,14 +418,12 @@ 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::<AtomicBool>()));
|
||||
/// assert!(ptr.cast::<AtomicBool>().is_aligned());
|
||||
///
|
||||
/// {
|
||||
/// // Create an atomic view of the allocated value
|
||||
@ -1216,14 +1214,12 @@ 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
|
||||
@ -2199,14 +2195,12 @@ macro_rules! atomic_int {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(pointer_is_aligned)]
|
||||
#[doc = concat!($extra_feature, "use std::sync::atomic::{self, ", stringify!($atomic_type), "};")]
|
||||
/// use std::mem::align_of;
|
||||
///
|
||||
/// // Get a pointer to an allocated value
|
||||
#[doc = concat!("let ptr: *mut ", stringify!($int_type), " = Box::into_raw(Box::new(0));")]
|
||||
///
|
||||
#[doc = concat!("assert!(ptr.is_aligned_to(align_of::<", stringify!($atomic_type), ">()));")]
|
||||
#[doc = concat!("assert!(ptr.cast::<", stringify!($atomic_type), ">().is_aligned());")]
|
||||
///
|
||||
/// {
|
||||
/// // Create an atomic view of the allocated value
|
||||
|
@ -95,7 +95,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)]
|
||||
|
@ -341,7 +341,7 @@
|
||||
#![feature(panic_can_unwind)]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(panic_internals)]
|
||||
#![feature(pointer_is_aligned)]
|
||||
#![feature(pointer_is_aligned_to)]
|
||||
#![feature(portable_simd)]
|
||||
#![feature(prelude_2024)]
|
||||
#![feature(ptr_as_uninit)]
|
||||
|
@ -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;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#![crate_type="rlib"]
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(pointer_is_aligned)]
|
||||
#![feature(pointer_is_aligned_to)]
|
||||
|
||||
// CHECK-LABEL: is_aligned_to_unchecked
|
||||
// CHECK: decq
|
||||
|
@ -1,7 +1,7 @@
|
||||
//@ run-pass
|
||||
//@ compile-flags: -C debug-assertions
|
||||
|
||||
#![feature(strict_provenance, pointer_is_aligned)]
|
||||
#![feature(strict_provenance)]
|
||||
|
||||
#[repr(packed)]
|
||||
struct Misaligner {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user