Skip to content

Commit fcedf3a

Browse files
committed
stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
This is an alternative to #121920
1 parent 279c9ba commit fcedf3a

File tree

12 files changed

+28
-50
lines changed

12 files changed

+28
-50
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
@@ -195,7 +195,6 @@
195195
#![feature(multiple_supertrait_upcastable)]
196196
#![feature(negative_impls)]
197197
#![feature(never_type)]
198-
#![feature(pointer_is_aligned)]
199198
#![feature(rustc_allow_const_fn_unstable)]
200199
#![feature(rustc_attrs)]
201200
#![feature(slice_internals)]

library/alloc/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#![feature(const_trait_impl)]
3737
#![feature(const_str_from_utf8)]
3838
#![feature(panic_update_hook)]
39-
#![feature(pointer_is_aligned)]
39+
#![feature(pointer_is_aligned_to)]
4040
#![feature(slice_flatten)]
4141
#![feature(thin_box)]
4242
#![feature(strict_provenance)]

library/core/src/ptr/const_ptr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,6 @@ impl<T: ?Sized> *const T {
13871387
/// # Examples
13881388
///
13891389
/// ```
1390-
/// #![feature(pointer_is_aligned)]
1391-
///
13921390
/// // On some platforms, the alignment of i32 is less than 4.
13931391
/// #[repr(align(4))]
13941392
/// struct AlignedI32(i32);
@@ -1411,7 +1409,6 @@ impl<T: ?Sized> *const T {
14111409
/// underlying allocation.
14121410
///
14131411
/// ```
1414-
/// #![feature(pointer_is_aligned)]
14151412
/// #![feature(const_pointer_is_aligned)]
14161413
///
14171414
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1437,7 +1434,6 @@ impl<T: ?Sized> *const T {
14371434
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14381435
///
14391436
/// ```
1440-
/// #![feature(pointer_is_aligned)]
14411437
/// #![feature(const_pointer_is_aligned)]
14421438
///
14431439
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1463,7 +1459,6 @@ impl<T: ?Sized> *const T {
14631459
/// runtime and compiletime.
14641460
///
14651461
/// ```
1466-
/// #![feature(pointer_is_aligned)]
14671462
/// #![feature(const_pointer_is_aligned)]
14681463
///
14691464
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1487,7 +1482,7 @@ impl<T: ?Sized> *const T {
14871482
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
14881483
#[must_use]
14891484
#[inline]
1490-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1485+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
14911486
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
14921487
pub const fn is_aligned(self) -> bool
14931488
where
@@ -1508,7 +1503,7 @@ impl<T: ?Sized> *const T {
15081503
/// # Examples
15091504
///
15101505
/// ```
1511-
/// #![feature(pointer_is_aligned)]
1506+
/// #![feature(pointer_is_aligned_to)]
15121507
///
15131508
/// // On some platforms, the alignment of i32 is less than 4.
15141509
/// #[repr(align(4))]
@@ -1537,7 +1532,7 @@ impl<T: ?Sized> *const T {
15371532
/// cannot be stricter aligned than the reference's underlying allocation.
15381533
///
15391534
/// ```
1540-
/// #![feature(pointer_is_aligned)]
1535+
/// #![feature(pointer_is_aligned_to)]
15411536
/// #![feature(const_pointer_is_aligned)]
15421537
///
15431538
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1562,7 +1557,7 @@ impl<T: ?Sized> *const T {
15621557
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
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.
@@ -1586,7 +1581,7 @@ impl<T: ?Sized> *const T {
15861581
/// runtime and compiletime.
15871582
///
15881583
/// ```
1589-
/// #![feature(pointer_is_aligned)]
1584+
/// #![feature(pointer_is_aligned_to)]
15901585
/// #![feature(const_pointer_is_aligned)]
15911586
///
15921587
/// const _: () = {
@@ -1602,7 +1597,7 @@ impl<T: ?Sized> *const T {
16021597
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
16031598
#[must_use]
16041599
#[inline]
1605-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1600+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
16061601
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
16071602
pub const fn is_aligned_to(self, align: usize) -> bool {
16081603
if !align.is_power_of_two() {

library/core/src/ptr/mut_ptr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1656,8 +1656,6 @@ impl<T: ?Sized> *mut T {
16561656
/// # Examples
16571657
///
16581658
/// ```
1659-
/// #![feature(pointer_is_aligned)]
1660-
///
16611659
/// // On some platforms, the alignment of i32 is less than 4.
16621660
/// #[repr(align(4))]
16631661
/// struct AlignedI32(i32);
@@ -1680,7 +1678,6 @@ impl<T: ?Sized> *mut T {
16801678
/// underlying allocation.
16811679
///
16821680
/// ```
1683-
/// #![feature(pointer_is_aligned)]
16841681
/// #![feature(const_pointer_is_aligned)]
16851682
/// #![feature(const_mut_refs)]
16861683
///
@@ -1707,7 +1704,6 @@ impl<T: ?Sized> *mut T {
17071704
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
17081705
///
17091706
/// ```
1710-
/// #![feature(pointer_is_aligned)]
17111707
/// #![feature(const_pointer_is_aligned)]
17121708
///
17131709
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1734,7 +1730,6 @@ impl<T: ?Sized> *mut T {
17341730
/// runtime and compiletime.
17351731
///
17361732
/// ```
1737-
/// #![feature(pointer_is_aligned)]
17381733
/// #![feature(const_pointer_is_aligned)]
17391734
///
17401735
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1758,7 +1753,7 @@ impl<T: ?Sized> *mut T {
17581753
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
17591754
#[must_use]
17601755
#[inline]
1761-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1756+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
17621757
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
17631758
pub const fn is_aligned(self) -> bool
17641759
where
@@ -1779,7 +1774,7 @@ impl<T: ?Sized> *mut T {
17791774
/// # Examples
17801775
///
17811776
/// ```
1782-
/// #![feature(pointer_is_aligned)]
1777+
/// #![feature(pointer_is_aligned_to)]
17831778
///
17841779
/// // On some platforms, the alignment of i32 is less than 4.
17851780
/// #[repr(align(4))]
@@ -1808,7 +1803,7 @@ impl<T: ?Sized> *mut T {
18081803
/// cannot be stricter aligned than the reference's underlying allocation.
18091804
///
18101805
/// ```
1811-
/// #![feature(pointer_is_aligned)]
1806+
/// #![feature(pointer_is_aligned_to)]
18121807
/// #![feature(const_pointer_is_aligned)]
18131808
/// #![feature(const_mut_refs)]
18141809
///
@@ -1834,7 +1829,7 @@ impl<T: ?Sized> *mut T {
18341829
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
18351830
///
18361831
/// ```
1837-
/// #![feature(pointer_is_aligned)]
1832+
/// #![feature(pointer_is_aligned_to)]
18381833
/// #![feature(const_pointer_is_aligned)]
18391834
///
18401835
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1859,7 +1854,7 @@ impl<T: ?Sized> *mut T {
18591854
/// runtime and compiletime.
18601855
///
18611856
/// ```
1862-
/// #![feature(pointer_is_aligned)]
1857+
/// #![feature(pointer_is_aligned_to)]
18631858
/// #![feature(const_pointer_is_aligned)]
18641859
///
18651860
/// const _: () = {
@@ -1875,7 +1870,7 @@ impl<T: ?Sized> *mut T {
18751870
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
18761871
#[must_use]
18771872
#[inline]
1878-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1873+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
18791874
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
18801875
pub const fn is_aligned_to(self, align: usize) -> bool {
18811876
if !align.is_power_of_two() {

library/core/src/ptr/non_null.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,6 @@ impl<T: ?Sized> NonNull<T> {
12891289
/// # Examples
12901290
///
12911291
/// ```
1292-
/// #![feature(pointer_is_aligned)]
12931292
/// use std::ptr::NonNull;
12941293
///
12951294
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1314,7 +1313,6 @@ impl<T: ?Sized> NonNull<T> {
13141313
/// underlying allocation.
13151314
///
13161315
/// ```
1317-
/// #![feature(pointer_is_aligned)]
13181316
/// #![feature(const_pointer_is_aligned)]
13191317
/// #![feature(non_null_convenience)]
13201318
/// #![feature(const_option)]
@@ -1344,7 +1342,6 @@ impl<T: ?Sized> NonNull<T> {
13441342
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
13451343
///
13461344
/// ```
1347-
/// #![feature(pointer_is_aligned)]
13481345
/// #![feature(const_pointer_is_aligned)]
13491346
///
13501347
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1370,7 +1367,6 @@ impl<T: ?Sized> NonNull<T> {
13701367
/// runtime and compiletime.
13711368
///
13721369
/// ```
1373-
/// #![feature(pointer_is_aligned)]
13741370
/// #![feature(const_pointer_is_aligned)]
13751371
/// #![feature(const_option)]
13761372
/// #![feature(const_nonnull_new)]
@@ -1395,7 +1391,7 @@ impl<T: ?Sized> NonNull<T> {
13951391
/// ```
13961392
///
13971393
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1398-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1394+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
13991395
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
14001396
#[must_use]
14011397
#[inline]
@@ -1418,7 +1414,7 @@ impl<T: ?Sized> NonNull<T> {
14181414
/// # Examples
14191415
///
14201416
/// ```
1421-
/// #![feature(pointer_is_aligned)]
1417+
/// #![feature(pointer_is_aligned_to)]
14221418
///
14231419
/// // On some platforms, the alignment of i32 is less than 4.
14241420
/// #[repr(align(4))]
@@ -1447,7 +1443,7 @@ impl<T: ?Sized> NonNull<T> {
14471443
/// cannot be stricter aligned than the reference's underlying allocation.
14481444
///
14491445
/// ```
1450-
/// #![feature(pointer_is_aligned)]
1446+
/// #![feature(pointer_is_aligned_to)]
14511447
/// #![feature(const_pointer_is_aligned)]
14521448
///
14531449
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1472,7 +1468,7 @@ impl<T: ?Sized> NonNull<T> {
14721468
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14731469
///
14741470
/// ```
1475-
/// #![feature(pointer_is_aligned)]
1471+
/// #![feature(pointer_is_aligned_to)]
14761472
/// #![feature(const_pointer_is_aligned)]
14771473
///
14781474
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1496,7 +1492,7 @@ impl<T: ?Sized> NonNull<T> {
14961492
/// runtime and compiletime.
14971493
///
14981494
/// ```
1499-
/// #![feature(pointer_is_aligned)]
1495+
/// #![feature(pointer_is_aligned_to)]
15001496
/// #![feature(const_pointer_is_aligned)]
15011497
///
15021498
/// const _: () = {
@@ -1510,7 +1506,7 @@ impl<T: ?Sized> NonNull<T> {
15101506
/// ```
15111507
///
15121508
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1513-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1509+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
15141510
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
15151511
#[must_use]
15161512
#[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
@@ -92,7 +92,7 @@
9292
#![feature(const_waker)]
9393
#![feature(never_type)]
9494
#![feature(unwrap_infallible)]
95-
#![feature(pointer_is_aligned)]
95+
#![feature(pointer_is_aligned_to)]
9696
#![feature(portable_simd)]
9797
#![feature(ptr_metadata)]
9898
#![feature(lazy_cell)]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@
339339
#![feature(panic_can_unwind)]
340340
#![feature(panic_info_message)]
341341
#![feature(panic_internals)]
342-
#![feature(pointer_is_aligned)]
343342
#![feature(portable_simd)]
344343
#![feature(prelude_2024)]
345344
#![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/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)