Skip to content

Commit 1a06483

Browse files
committed
Auto merge of #121948 - Gankra:stab-align, r=dtolnay
stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate This is an alternative to #121920
2 parents 7aa1de7 + 6f8a40e commit 1a06483

File tree

13 files changed

+29
-51
lines changed

13 files changed

+29
-51
lines changed

compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ index d0a119c..76fdece 100644
1414
@@ -89,7 +89,6 @@
1515
#![feature(never_type)]
1616
#![feature(unwrap_infallible)]
17-
#![feature(pointer_is_aligned)]
17+
#![feature(pointer_is_aligned_to)]
1818
-#![feature(portable_simd)]
1919
#![feature(ptr_metadata)]
2020
#![feature(lazy_cell)]
@@ -27,6 +27,6 @@ index d0a119c..76fdece 100644
2727
mod slice;
2828
mod str;
2929
mod str_lossy;
30-
--
30+
--
3131
2.42.1
3232

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
#![feature(multiple_supertrait_upcastable)]
197197
#![feature(negative_impls)]
198198
#![feature(never_type)]
199-
#![feature(pointer_is_aligned)]
200199
#![feature(rustc_allow_const_fn_unstable)]
201200
#![feature(rustc_attrs)]
202201
#![feature(slice_internals)]

library/alloc/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#![feature(const_trait_impl)]
3838
#![feature(const_str_from_utf8)]
3939
#![feature(panic_update_hook)]
40-
#![feature(pointer_is_aligned)]
40+
#![feature(pointer_is_aligned_to)]
4141
#![feature(slice_flatten)]
4242
#![feature(thin_box)]
4343
#![feature(strict_provenance)]

library/core/src/ptr/const_ptr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,6 @@ impl<T: ?Sized> *const T {
14121412
/// # Examples
14131413
///
14141414
/// ```
1415-
/// #![feature(pointer_is_aligned)]
1416-
///
14171415
/// // On some platforms, the alignment of i32 is less than 4.
14181416
/// #[repr(align(4))]
14191417
/// struct AlignedI32(i32);
@@ -1436,7 +1434,6 @@ impl<T: ?Sized> *const T {
14361434
/// underlying allocation.
14371435
///
14381436
/// ```
1439-
/// #![feature(pointer_is_aligned)]
14401437
/// #![feature(const_pointer_is_aligned)]
14411438
///
14421439
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1462,7 +1459,6 @@ impl<T: ?Sized> *const T {
14621459
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14631460
///
14641461
/// ```
1465-
/// #![feature(pointer_is_aligned)]
14661462
/// #![feature(const_pointer_is_aligned)]
14671463
///
14681464
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1488,7 +1484,6 @@ impl<T: ?Sized> *const T {
14881484
/// runtime and compiletime.
14891485
///
14901486
/// ```
1491-
/// #![feature(pointer_is_aligned)]
14921487
/// #![feature(const_pointer_is_aligned)]
14931488
///
14941489
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1512,7 +1507,7 @@ impl<T: ?Sized> *const T {
15121507
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
15131508
#[must_use]
15141509
#[inline]
1515-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1510+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
15161511
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
15171512
pub const fn is_aligned(self) -> bool
15181513
where
@@ -1533,7 +1528,7 @@ impl<T: ?Sized> *const T {
15331528
/// # Examples
15341529
///
15351530
/// ```
1536-
/// #![feature(pointer_is_aligned)]
1531+
/// #![feature(pointer_is_aligned_to)]
15371532
///
15381533
/// // On some platforms, the alignment of i32 is less than 4.
15391534
/// #[repr(align(4))]
@@ -1562,7 +1557,7 @@ impl<T: ?Sized> *const T {
15621557
/// cannot be stricter aligned than the reference's underlying allocation.
15631558
///
15641559
/// ```
1565-
/// #![feature(pointer_is_aligned)]
1560+
/// #![feature(pointer_is_aligned_to)]
15661561
/// #![feature(const_pointer_is_aligned)]
15671562
///
15681563
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1587,7 +1582,7 @@ impl<T: ?Sized> *const T {
15871582
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
15881583
///
15891584
/// ```
1590-
/// #![feature(pointer_is_aligned)]
1585+
/// #![feature(pointer_is_aligned_to)]
15911586
/// #![feature(const_pointer_is_aligned)]
15921587
///
15931588
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1611,7 +1606,7 @@ impl<T: ?Sized> *const T {
16111606
/// runtime and compiletime.
16121607
///
16131608
/// ```
1614-
/// #![feature(pointer_is_aligned)]
1609+
/// #![feature(pointer_is_aligned_to)]
16151610
/// #![feature(const_pointer_is_aligned)]
16161611
///
16171612
/// const _: () = {
@@ -1627,7 +1622,7 @@ impl<T: ?Sized> *const T {
16271622
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
16281623
#[must_use]
16291624
#[inline]
1630-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1625+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
16311626
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
16321627
pub const fn is_aligned_to(self, align: usize) -> bool {
16331628
if !align.is_power_of_two() {

library/core/src/ptr/mut_ptr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1666,8 +1666,6 @@ impl<T: ?Sized> *mut T {
16661666
/// # Examples
16671667
///
16681668
/// ```
1669-
/// #![feature(pointer_is_aligned)]
1670-
///
16711669
/// // On some platforms, the alignment of i32 is less than 4.
16721670
/// #[repr(align(4))]
16731671
/// struct AlignedI32(i32);
@@ -1690,7 +1688,6 @@ impl<T: ?Sized> *mut T {
16901688
/// underlying allocation.
16911689
///
16921690
/// ```
1693-
/// #![feature(pointer_is_aligned)]
16941691
/// #![feature(const_pointer_is_aligned)]
16951692
/// #![feature(const_mut_refs)]
16961693
///
@@ -1717,7 +1714,6 @@ impl<T: ?Sized> *mut T {
17171714
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
17181715
///
17191716
/// ```
1720-
/// #![feature(pointer_is_aligned)]
17211717
/// #![feature(const_pointer_is_aligned)]
17221718
///
17231719
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1744,7 +1740,6 @@ impl<T: ?Sized> *mut T {
17441740
/// runtime and compiletime.
17451741
///
17461742
/// ```
1747-
/// #![feature(pointer_is_aligned)]
17481743
/// #![feature(const_pointer_is_aligned)]
17491744
///
17501745
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1768,7 +1763,7 @@ impl<T: ?Sized> *mut T {
17681763
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
17691764
#[must_use]
17701765
#[inline]
1771-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1766+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
17721767
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
17731768
pub const fn is_aligned(self) -> bool
17741769
where
@@ -1789,7 +1784,7 @@ impl<T: ?Sized> *mut T {
17891784
/// # Examples
17901785
///
17911786
/// ```
1792-
/// #![feature(pointer_is_aligned)]
1787+
/// #![feature(pointer_is_aligned_to)]
17931788
///
17941789
/// // On some platforms, the alignment of i32 is less than 4.
17951790
/// #[repr(align(4))]
@@ -1818,7 +1813,7 @@ impl<T: ?Sized> *mut T {
18181813
/// cannot be stricter aligned than the reference's underlying allocation.
18191814
///
18201815
/// ```
1821-
/// #![feature(pointer_is_aligned)]
1816+
/// #![feature(pointer_is_aligned_to)]
18221817
/// #![feature(const_pointer_is_aligned)]
18231818
/// #![feature(const_mut_refs)]
18241819
///
@@ -1844,7 +1839,7 @@ impl<T: ?Sized> *mut T {
18441839
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
18451840
///
18461841
/// ```
1847-
/// #![feature(pointer_is_aligned)]
1842+
/// #![feature(pointer_is_aligned_to)]
18481843
/// #![feature(const_pointer_is_aligned)]
18491844
///
18501845
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1869,7 +1864,7 @@ impl<T: ?Sized> *mut T {
18691864
/// runtime and compiletime.
18701865
///
18711866
/// ```
1872-
/// #![feature(pointer_is_aligned)]
1867+
/// #![feature(pointer_is_aligned_to)]
18731868
/// #![feature(const_pointer_is_aligned)]
18741869
///
18751870
/// const _: () = {
@@ -1885,7 +1880,7 @@ impl<T: ?Sized> *mut T {
18851880
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
18861881
#[must_use]
18871882
#[inline]
1888-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1883+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
18891884
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
18901885
pub const fn is_aligned_to(self, align: usize) -> bool {
18911886
if !align.is_power_of_two() {

library/core/src/ptr/non_null.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,6 @@ impl<T: ?Sized> NonNull<T> {
12901290
/// # Examples
12911291
///
12921292
/// ```
1293-
/// #![feature(pointer_is_aligned)]
12941293
/// use std::ptr::NonNull;
12951294
///
12961295
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1315,7 +1314,6 @@ impl<T: ?Sized> NonNull<T> {
13151314
/// underlying allocation.
13161315
///
13171316
/// ```
1318-
/// #![feature(pointer_is_aligned)]
13191317
/// #![feature(const_pointer_is_aligned)]
13201318
/// #![feature(non_null_convenience)]
13211319
/// #![feature(const_option)]
@@ -1345,7 +1343,6 @@ impl<T: ?Sized> NonNull<T> {
13451343
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
13461344
///
13471345
/// ```
1348-
/// #![feature(pointer_is_aligned)]
13491346
/// #![feature(const_pointer_is_aligned)]
13501347
///
13511348
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1371,7 +1368,6 @@ impl<T: ?Sized> NonNull<T> {
13711368
/// runtime and compiletime.
13721369
///
13731370
/// ```
1374-
/// #![feature(pointer_is_aligned)]
13751371
/// #![feature(const_pointer_is_aligned)]
13761372
/// #![feature(const_option)]
13771373
/// #![feature(const_nonnull_new)]
@@ -1396,7 +1392,7 @@ impl<T: ?Sized> NonNull<T> {
13961392
/// ```
13971393
///
13981394
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1399-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1395+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
14001396
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
14011397
#[must_use]
14021398
#[inline]
@@ -1419,7 +1415,7 @@ impl<T: ?Sized> NonNull<T> {
14191415
/// # Examples
14201416
///
14211417
/// ```
1422-
/// #![feature(pointer_is_aligned)]
1418+
/// #![feature(pointer_is_aligned_to)]
14231419
///
14241420
/// // On some platforms, the alignment of i32 is less than 4.
14251421
/// #[repr(align(4))]
@@ -1448,7 +1444,7 @@ impl<T: ?Sized> NonNull<T> {
14481444
/// cannot be stricter aligned than the reference's underlying allocation.
14491445
///
14501446
/// ```
1451-
/// #![feature(pointer_is_aligned)]
1447+
/// #![feature(pointer_is_aligned_to)]
14521448
/// #![feature(const_pointer_is_aligned)]
14531449
///
14541450
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1473,7 +1469,7 @@ impl<T: ?Sized> NonNull<T> {
14731469
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14741470
///
14751471
/// ```
1476-
/// #![feature(pointer_is_aligned)]
1472+
/// #![feature(pointer_is_aligned_to)]
14771473
/// #![feature(const_pointer_is_aligned)]
14781474
///
14791475
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1497,7 +1493,7 @@ impl<T: ?Sized> NonNull<T> {
14971493
/// runtime and compiletime.
14981494
///
14991495
/// ```
1500-
/// #![feature(pointer_is_aligned)]
1496+
/// #![feature(pointer_is_aligned_to)]
15011497
/// #![feature(const_pointer_is_aligned)]
15021498
///
15031499
/// const _: () = {
@@ -1511,7 +1507,7 @@ impl<T: ?Sized> NonNull<T> {
15111507
/// ```
15121508
///
15131509
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1514-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1510+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
15151511
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
15161512
#[must_use]
15171513
#[inline]

library/core/src/sync/atomic.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,12 @@ impl AtomicBool {
418418
/// # Examples
419419
///
420420
/// ```
421-
/// #![feature(pointer_is_aligned)]
422421
/// use std::sync::atomic::{self, AtomicBool};
423-
/// use std::mem::align_of;
424422
///
425423
/// // Get a pointer to an allocated value
426424
/// let ptr: *mut bool = Box::into_raw(Box::new(false));
427425
///
428-
/// assert!(ptr.is_aligned_to(align_of::<AtomicBool>()));
426+
/// assert!(ptr.cast::<AtomicBool>().is_aligned());
429427
///
430428
/// {
431429
/// // Create an atomic view of the allocated value
@@ -1216,14 +1214,12 @@ impl<T> AtomicPtr<T> {
12161214
/// # Examples
12171215
///
12181216
/// ```
1219-
/// #![feature(pointer_is_aligned)]
12201217
/// use std::sync::atomic::{self, AtomicPtr};
1221-
/// use std::mem::align_of;
12221218
///
12231219
/// // Get a pointer to an allocated value
12241220
/// let ptr: *mut *mut u8 = Box::into_raw(Box::new(std::ptr::null_mut()));
12251221
///
1226-
/// assert!(ptr.is_aligned_to(align_of::<AtomicPtr<u8>>()));
1222+
/// assert!(ptr.cast::<AtomicPtr<u8>>().is_aligned());
12271223
///
12281224
/// {
12291225
/// // Create an atomic view of the allocated value
@@ -2199,14 +2195,12 @@ macro_rules! atomic_int {
21992195
/// # Examples
22002196
///
22012197
/// ```
2202-
/// #![feature(pointer_is_aligned)]
22032198
#[doc = concat!($extra_feature, "use std::sync::atomic::{self, ", stringify!($atomic_type), "};")]
2204-
/// use std::mem::align_of;
22052199
///
22062200
/// // Get a pointer to an allocated value
22072201
#[doc = concat!("let ptr: *mut ", stringify!($int_type), " = Box::into_raw(Box::new(0));")]
22082202
///
2209-
#[doc = concat!("assert!(ptr.is_aligned_to(align_of::<", stringify!($atomic_type), ">()));")]
2203+
#[doc = concat!("assert!(ptr.cast::<", stringify!($atomic_type), ">().is_aligned());")]
22102204
///
22112205
/// {
22122206
/// // Create an atomic view of the allocated value

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
#![feature(const_waker)]
9494
#![feature(never_type)]
9595
#![feature(unwrap_infallible)]
96-
#![feature(pointer_is_aligned)]
96+
#![feature(pointer_is_aligned_to)]
9797
#![feature(portable_simd)]
9898
#![feature(ptr_metadata)]
9999
#![feature(lazy_cell)]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@
341341
#![feature(panic_can_unwind)]
342342
#![feature(panic_info_message)]
343343
#![feature(panic_internals)]
344-
#![feature(pointer_is_aligned)]
345344
#![feature(portable_simd)]
346345
#![feature(prelude_2024)]
347346
#![feature(ptr_as_uninit)]

src/tools/miri/tests/pass-dep/shims/posix_memalign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ignore-target-windows: No libc on Windows
22

3-
#![feature(pointer_is_aligned)]
3+
#![feature(pointer_is_aligned_to)]
44
#![feature(strict_provenance)]
55

66
use core::ptr;

tests/assembly/is_aligned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![crate_type="rlib"]
88

99
#![feature(core_intrinsics)]
10-
#![feature(pointer_is_aligned)]
10+
#![feature(pointer_is_aligned_to)]
1111

1212
// CHECK-LABEL: is_aligned_to_unchecked
1313
// CHECK: decq

tests/ui/mir/alignment/packed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
//@ compile-flags: -C debug-assertions
33

4-
#![feature(strict_provenance, pointer_is_aligned)]
4+
#![feature(strict_provenance)]
55

66
#[repr(packed)]
77
struct Misaligner {

tests/ui/structs-enums/type-sizes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(dead_code)]
55
#![feature(generic_nonzero)]
66
#![feature(never_type)]
7-
#![feature(pointer_is_aligned)]
7+
#![feature(pointer_is_aligned_to)]
88
#![feature(strict_provenance)]
99

1010
use std::mem::size_of;

0 commit comments

Comments
 (0)