Skip to content

Commit 477a37d

Browse files
committed
Partially stabilize ptr_alignment_type as alignment_type
1 parent 765fd2d commit 477a37d

File tree

21 files changed

+100
-68
lines changed

21 files changed

+100
-68
lines changed

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl AllocFnFactory<'_, '_> {
180180
}
181181

182182
fn ptr_alignment(&self) -> Box<Ty> {
183-
let path = self.cx.std_path(&[sym::ptr, sym::Alignment]);
183+
let path = self.cx.std_path(&[sym::mem, sym::Alignment]);
184184
let path = self.cx.path(self.span, path);
185185
self.cx.ty_path(path)
186186
}

compiler/rustc_data_structures/src/aligned.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use std::marker::PointeeSized;
2+
#[cfg(not(bootstrap))]
3+
use std::mem::Alignment;
4+
#[cfg(bootstrap)]
25
use std::ptr::Alignment;
36

47
/// Returns the ABI-required minimum alignment of a type in bytes.

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![cfg_attr(bootstrap, feature(assert_matches))]
1414
#![cfg_attr(bootstrap, feature(cfg_select))]
1515
#![cfg_attr(bootstrap, feature(cold_path))]
16+
#![cfg_attr(bootstrap, feature(ptr_alignment_type))]
1617
#![cfg_attr(test, feature(test))]
1718
#![deny(unsafe_op_in_unsafe_fn)]
1819
#![feature(allocator_api)]
@@ -28,7 +29,6 @@
2829
#![feature(min_specialization)]
2930
#![feature(negative_impls)]
3031
#![feature(never_type)]
31-
#![feature(ptr_alignment_type)]
3232
#![feature(rustc_attrs)]
3333
#![feature(sized_hierarchy)]
3434
#![feature(thread_id_value)]

compiler/rustc_data_structures/src/tagged_ptr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ pub unsafe trait Tag: Copy {
5555
/// Returns the number of bits available for use for tags in a pointer to `T`
5656
/// (this is based on `T`'s alignment).
5757
pub const fn bits_for<T: ?Sized + Aligned>() -> u32 {
58-
crate::aligned::align_of::<T>().as_nonzero().trailing_zeros()
58+
let alignment = crate::aligned::align_of::<T>();
59+
#[cfg(bootstrap)]
60+
let alignment = alignment.as_nonzero();
61+
#[cfg(not(bootstrap))]
62+
let alignment = alignment.as_nonzero_usize();
63+
alignment.trailing_zeros()
5964
}
6065

6166
/// Returns the correct [`Tag::BITS`] constant for a set of tag values.

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![allow(rustc::direct_use_of_rustc_type_ir)]
3030
#![cfg_attr(bootstrap, feature(assert_matches))]
3131
#![cfg_attr(bootstrap, feature(if_let_guard))]
32+
#![cfg_attr(bootstrap, feature(ptr_alignment_type))]
3233
#![cfg_attr(doc, feature(intra_doc_pointers))]
3334
#![feature(allocator_api)]
3435
#![feature(associated_type_defaults)]
@@ -47,7 +48,6 @@
4748
#![feature(min_specialization)]
4849
#![feature(negative_impls)]
4950
#![feature(never_type)]
50-
#![feature(ptr_alignment_type)]
5151
#![feature(range_bounds_is_empty)]
5252
#![feature(rustc_attrs)]
5353
#![feature(sized_hierarchy)]

compiler/rustc_middle/src/ty/list.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ unsafe impl<H: DynSync, T: DynSync> DynSync for RawList<H, T> {}
264264
// Layouts of `ListSkeleton<H, T>` and `RawList<H, T>` are the same, modulo opaque tail,
265265
// thus aligns of `ListSkeleton<H, T>` and `RawList<H, T>` must be the same.
266266
unsafe impl<H, T> Aligned for RawList<H, T> {
267+
#[cfg(bootstrap)]
267268
const ALIGN: ptr::Alignment = align_of::<ListSkeleton<H, T>>();
269+
#[cfg(not(bootstrap))]
270+
const ALIGN: mem::Alignment = align_of::<ListSkeleton<H, T>>();
268271
}
269272

270273
/// A [`List`] that additionally stores type information inline to speed up

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ symbols! {
12331233
maybe_uninit,
12341234
maybe_uninit_uninit,
12351235
maybe_uninit_zeroed,
1236+
mem,
12361237
mem_align_const,
12371238
mem_discriminant,
12381239
mem_drop,

library/alloc/src/alloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#[stable(feature = "alloc_module", since = "1.28.0")]
66
#[doc(inline)]
77
pub use core::alloc::*;
8-
use core::ptr::{self, Alignment, NonNull};
8+
use core::mem::Alignment;
9+
use core::ptr::{self, NonNull};
910
use core::{cmp, hint};
1011

1112
unsafe extern "Rust" {

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
#![feature(panic_internals)]
136136
#![feature(pattern)]
137137
#![feature(pin_coerce_unsized_trait)]
138-
#![feature(ptr_alignment_type)]
139138
#![feature(ptr_internals)]
140139
#![feature(ptr_metadata)]
141140
#![feature(rev_into_inner)]

library/alloc/src/raw_vec/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// run the tests. See the comment there for an explanation why this is the case.
66

77
use core::marker::{Destruct, PhantomData};
8-
use core::mem::{ManuallyDrop, MaybeUninit, SizedTypeProperties};
9-
use core::ptr::{self, Alignment, NonNull, Unique};
8+
use core::mem::{Alignment, ManuallyDrop, MaybeUninit, SizedTypeProperties};
9+
use core::ptr::{self, NonNull, Unique};
1010
use core::{cmp, hint};
1111

1212
#[cfg(not(no_global_oom_handling))]
@@ -569,7 +569,7 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
569569
impl<A: Allocator> RawVecInner<A> {
570570
#[inline]
571571
const fn new_in(alloc: A, align: Alignment) -> Self {
572-
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero()));
572+
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero_usize()));
573573
// `cap: 0` means "unallocated". zero-sized types are ignored.
574574
Self { ptr, cap: ZERO_CAP, alloc }
575575
}

0 commit comments

Comments
 (0)