Skip to content

Commit ea92fae

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 faae5f1 commit ea92fae

File tree

13 files changed

+30
-51
lines changed

13 files changed

+30
-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
@@ -198,7 +198,6 @@
198198
#![feature(multiple_supertrait_upcastable)]
199199
#![feature(negative_impls)]
200200
#![feature(never_type)]
201-
#![feature(pointer_is_aligned)]
202201
#![feature(rustc_allow_const_fn_unstable)]
203202
#![feature(rustc_attrs)]
204203
#![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
@@ -1401,8 +1401,6 @@ impl<T: ?Sized> *const T {
14011401
/// # Examples
14021402
///
14031403
/// ```
1404-
/// #![feature(pointer_is_aligned)]
1405-
///
14061404
/// // On some platforms, the alignment of i32 is less than 4.
14071405
/// #[repr(align(4))]
14081406
/// struct AlignedI32(i32);
@@ -1425,7 +1423,6 @@ impl<T: ?Sized> *const T {
14251423
/// underlying allocation.
14261424
///
14271425
/// ```
1428-
/// #![feature(pointer_is_aligned)]
14291426
/// #![feature(const_pointer_is_aligned)]
14301427
///
14311428
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1451,7 +1448,6 @@ impl<T: ?Sized> *const T {
14511448
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14521449
///
14531450
/// ```
1454-
/// #![feature(pointer_is_aligned)]
14551451
/// #![feature(const_pointer_is_aligned)]
14561452
///
14571453
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1477,7 +1473,6 @@ impl<T: ?Sized> *const T {
14771473
/// runtime and compiletime.
14781474
///
14791475
/// ```
1480-
/// #![feature(pointer_is_aligned)]
14811476
/// #![feature(const_pointer_is_aligned)]
14821477
///
14831478
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1501,7 +1496,7 @@ impl<T: ?Sized> *const T {
15011496
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
15021497
#[must_use]
15031498
#[inline]
1504-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1499+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
15051500
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
15061501
pub const fn is_aligned(self) -> bool
15071502
where
@@ -1522,7 +1517,7 @@ impl<T: ?Sized> *const T {
15221517
/// # Examples
15231518
///
15241519
/// ```
1525-
/// #![feature(pointer_is_aligned)]
1520+
/// #![feature(pointer_is_aligned_to)]
15261521
///
15271522
/// // On some platforms, the alignment of i32 is less than 4.
15281523
/// #[repr(align(4))]
@@ -1551,7 +1546,7 @@ impl<T: ?Sized> *const T {
15511546
/// cannot be stricter aligned than the reference's underlying allocation.
15521547
///
15531548
/// ```
1554-
/// #![feature(pointer_is_aligned)]
1549+
/// #![feature(pointer_is_aligned_to)]
15551550
/// #![feature(const_pointer_is_aligned)]
15561551
///
15571552
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1576,7 +1571,7 @@ impl<T: ?Sized> *const T {
15761571
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
15771572
///
15781573
/// ```
1579-
/// #![feature(pointer_is_aligned)]
1574+
/// #![feature(pointer_is_aligned_to)]
15801575
/// #![feature(const_pointer_is_aligned)]
15811576
///
15821577
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1600,7 +1595,7 @@ impl<T: ?Sized> *const T {
16001595
/// runtime and compiletime.
16011596
///
16021597
/// ```
1603-
/// #![feature(pointer_is_aligned)]
1598+
/// #![feature(pointer_is_aligned_to)]
16041599
/// #![feature(const_pointer_is_aligned)]
16051600
///
16061601
/// const _: () = {
@@ -1616,7 +1611,7 @@ impl<T: ?Sized> *const T {
16161611
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
16171612
#[must_use]
16181613
#[inline]
1619-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1614+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
16201615
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
16211616
pub const fn is_aligned_to(self, align: usize) -> bool {
16221617
if !align.is_power_of_two() {

library/core/src/ptr/mut_ptr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1660,8 +1660,6 @@ impl<T: ?Sized> *mut T {
16601660
/// # Examples
16611661
///
16621662
/// ```
1663-
/// #![feature(pointer_is_aligned)]
1664-
///
16651663
/// // On some platforms, the alignment of i32 is less than 4.
16661664
/// #[repr(align(4))]
16671665
/// struct AlignedI32(i32);
@@ -1684,7 +1682,6 @@ impl<T: ?Sized> *mut T {
16841682
/// underlying allocation.
16851683
///
16861684
/// ```
1687-
/// #![feature(pointer_is_aligned)]
16881685
/// #![feature(const_pointer_is_aligned)]
16891686
/// #![feature(const_mut_refs)]
16901687
///
@@ -1711,7 +1708,6 @@ impl<T: ?Sized> *mut T {
17111708
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
17121709
///
17131710
/// ```
1714-
/// #![feature(pointer_is_aligned)]
17151711
/// #![feature(const_pointer_is_aligned)]
17161712
///
17171713
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1738,7 +1734,6 @@ impl<T: ?Sized> *mut T {
17381734
/// runtime and compiletime.
17391735
///
17401736
/// ```
1741-
/// #![feature(pointer_is_aligned)]
17421737
/// #![feature(const_pointer_is_aligned)]
17431738
///
17441739
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1762,7 +1757,7 @@ impl<T: ?Sized> *mut T {
17621757
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
17631758
#[must_use]
17641759
#[inline]
1765-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1760+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
17661761
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
17671762
pub const fn is_aligned(self) -> bool
17681763
where
@@ -1783,7 +1778,7 @@ impl<T: ?Sized> *mut T {
17831778
/// # Examples
17841779
///
17851780
/// ```
1786-
/// #![feature(pointer_is_aligned)]
1781+
/// #![feature(pointer_is_aligned_to)]
17871782
///
17881783
/// // On some platforms, the alignment of i32 is less than 4.
17891784
/// #[repr(align(4))]
@@ -1812,7 +1807,7 @@ impl<T: ?Sized> *mut T {
18121807
/// cannot be stricter aligned than the reference's underlying allocation.
18131808
///
18141809
/// ```
1815-
/// #![feature(pointer_is_aligned)]
1810+
/// #![feature(pointer_is_aligned_to)]
18161811
/// #![feature(const_pointer_is_aligned)]
18171812
/// #![feature(const_mut_refs)]
18181813
///
@@ -1838,7 +1833,7 @@ impl<T: ?Sized> *mut T {
18381833
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
18391834
///
18401835
/// ```
1841-
/// #![feature(pointer_is_aligned)]
1836+
/// #![feature(pointer_is_aligned_to)]
18421837
/// #![feature(const_pointer_is_aligned)]
18431838
///
18441839
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1863,7 +1858,7 @@ impl<T: ?Sized> *mut T {
18631858
/// runtime and compiletime.
18641859
///
18651860
/// ```
1866-
/// #![feature(pointer_is_aligned)]
1861+
/// #![feature(pointer_is_aligned_to)]
18671862
/// #![feature(const_pointer_is_aligned)]
18681863
///
18691864
/// const _: () = {
@@ -1879,7 +1874,7 @@ impl<T: ?Sized> *mut T {
18791874
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
18801875
#[must_use]
18811876
#[inline]
1882-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1877+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
18831878
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
18841879
pub const fn is_aligned_to(self, align: usize) -> bool {
18851880
if !align.is_power_of_two() {

library/core/src/ptr/non_null.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,6 @@ impl<T: ?Sized> NonNull<T> {
12881288
/// # Examples
12891289
///
12901290
/// ```
1291-
/// #![feature(pointer_is_aligned)]
12921291
/// use std::ptr::NonNull;
12931292
///
12941293
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1313,7 +1312,6 @@ impl<T: ?Sized> NonNull<T> {
13131312
/// underlying allocation.
13141313
///
13151314
/// ```
1316-
/// #![feature(pointer_is_aligned)]
13171315
/// #![feature(const_pointer_is_aligned)]
13181316
/// #![feature(non_null_convenience)]
13191317
/// #![feature(const_option)]
@@ -1343,7 +1341,6 @@ impl<T: ?Sized> NonNull<T> {
13431341
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
13441342
///
13451343
/// ```
1346-
/// #![feature(pointer_is_aligned)]
13471344
/// #![feature(const_pointer_is_aligned)]
13481345
///
13491346
/// // On some platforms, the alignment of primitives is less than their size.
@@ -1369,7 +1366,6 @@ impl<T: ?Sized> NonNull<T> {
13691366
/// runtime and compiletime.
13701367
///
13711368
/// ```
1372-
/// #![feature(pointer_is_aligned)]
13731369
/// #![feature(const_pointer_is_aligned)]
13741370
/// #![feature(const_option)]
13751371
/// #![feature(const_nonnull_new)]
@@ -1394,7 +1390,7 @@ impl<T: ?Sized> NonNull<T> {
13941390
/// ```
13951391
///
13961392
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1397-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1393+
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
13981394
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
13991395
#[must_use]
14001396
#[inline]
@@ -1417,7 +1413,7 @@ impl<T: ?Sized> NonNull<T> {
14171413
/// # Examples
14181414
///
14191415
/// ```
1420-
/// #![feature(pointer_is_aligned)]
1416+
/// #![feature(pointer_is_aligned_to)]
14211417
///
14221418
/// // On some platforms, the alignment of i32 is less than 4.
14231419
/// #[repr(align(4))]
@@ -1446,7 +1442,7 @@ impl<T: ?Sized> NonNull<T> {
14461442
/// cannot be stricter aligned than the reference's underlying allocation.
14471443
///
14481444
/// ```
1449-
/// #![feature(pointer_is_aligned)]
1445+
/// #![feature(pointer_is_aligned_to)]
14501446
/// #![feature(const_pointer_is_aligned)]
14511447
///
14521448
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1471,7 +1467,7 @@ impl<T: ?Sized> NonNull<T> {
14711467
/// pointer is aligned, even if the compiletime pointer wasn't aligned.
14721468
///
14731469
/// ```
1474-
/// #![feature(pointer_is_aligned)]
1470+
/// #![feature(pointer_is_aligned_to)]
14751471
/// #![feature(const_pointer_is_aligned)]
14761472
///
14771473
/// // On some platforms, the alignment of i32 is less than 4.
@@ -1495,7 +1491,7 @@ impl<T: ?Sized> NonNull<T> {
14951491
/// runtime and compiletime.
14961492
///
14971493
/// ```
1498-
/// #![feature(pointer_is_aligned)]
1494+
/// #![feature(pointer_is_aligned_to)]
14991495
/// #![feature(const_pointer_is_aligned)]
15001496
///
15011497
/// const _: () = {
@@ -1509,7 +1505,7 @@ impl<T: ?Sized> NonNull<T> {
15091505
/// ```
15101506
///
15111507
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
1512-
#[unstable(feature = "pointer_is_aligned", issue = "96284")]
1508+
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
15131509
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
15141510
#[must_use]
15151511
#[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
@@ -95,7 +95,7 @@
9595
#![feature(const_waker)]
9696
#![feature(never_type)]
9797
#![feature(unwrap_infallible)]
98-
#![feature(pointer_is_aligned)]
98+
#![feature(pointer_is_aligned_to)]
9999
#![feature(portable_simd)]
100100
#![feature(ptr_metadata)]
101101
#![feature(lazy_cell)]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
#![feature(panic_can_unwind)]
342342
#![feature(panic_info_message)]
343343
#![feature(panic_internals)]
344-
#![feature(pointer_is_aligned)]
344+
#![feature(pointer_is_aligned_to)]
345345
#![feature(portable_simd)]
346346
#![feature(prelude_2024)]
347347
#![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)