Skip to content

Commit 63220ce

Browse files
Rollup merge of rust-lang#154004 - GrigorenkoPV:alignment/as_nonzero_usize, r=scottmcm
`Alignment`: move from `ptr` to `mem` and rename `as_nonzero` to `as_nonzero_usize` - tracking issue: rust-lang#102070 - split off from rust-lang#153261
2 parents 75bcc86 + ba1e06a commit 63220ce

41 files changed

Lines changed: 129 additions & 100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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/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/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
@@ -1227,6 +1227,7 @@ symbols! {
12271227
maybe_uninit,
12281228
maybe_uninit_uninit,
12291229
maybe_uninit_zeroed,
1230+
mem,
12301231
mem_align_const,
12311232
mem_discriminant,
12321233
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/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))]
@@ -570,7 +570,7 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
570570
impl<A: Allocator> RawVecInner<A> {
571571
#[inline]
572572
const fn new_in(alloc: A, align: Alignment) -> Self {
573-
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero()));
573+
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero_usize()));
574574
// `cap: 0` means "unallocated". zero-sized types are ignored.
575575
Self { ptr, cap: ZERO_CAP, alloc }
576576
}

library/alloc/src/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ use core::intrinsics::abort;
252252
#[cfg(not(no_global_oom_handling))]
253253
use core::iter;
254254
use core::marker::{PhantomData, Unsize};
255-
use core::mem::{self, ManuallyDrop};
255+
use core::mem::{self, Alignment, ManuallyDrop};
256256
use core::num::NonZeroUsize;
257257
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
258258
#[cfg(not(no_global_oom_handling))]
@@ -261,7 +261,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
261261
#[cfg(not(no_global_oom_handling))]
262262
use core::pin::Pin;
263263
use core::pin::PinCoerceUnsized;
264-
use core::ptr::{self, Alignment, NonNull, drop_in_place};
264+
use core::ptr::{self, NonNull, drop_in_place};
265265
#[cfg(not(no_global_oom_handling))]
266266
use core::slice::from_raw_parts_mut;
267267
use core::{borrow, fmt, hint};

library/alloc/src/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use core::intrinsics::abort;
1919
#[cfg(not(no_global_oom_handling))]
2020
use core::iter;
2121
use core::marker::{PhantomData, Unsize};
22-
use core::mem::{self, ManuallyDrop};
22+
use core::mem::{self, Alignment, ManuallyDrop};
2323
use core::num::NonZeroUsize;
2424
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
2525
#[cfg(not(no_global_oom_handling))]
2626
use core::ops::{Residual, Try};
2727
use core::panic::{RefUnwindSafe, UnwindSafe};
2828
use core::pin::{Pin, PinCoerceUnsized};
29-
use core::ptr::{self, Alignment, NonNull};
29+
use core::ptr::{self, NonNull};
3030
#[cfg(not(no_global_oom_handling))]
3131
use core::slice::from_raw_parts_mut;
3232
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};

library/core/src/alloc/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use crate::error::Error;
88
use crate::intrinsics::{unchecked_add, unchecked_mul, unchecked_sub};
9-
use crate::mem::SizedTypeProperties;
10-
use crate::ptr::{Alignment, NonNull};
9+
use crate::mem::{Alignment, SizedTypeProperties};
10+
use crate::ptr::NonNull;
1111
use crate::{assert_unsafe_precondition, fmt, mem};
1212

1313
/// Layout of a block of memory.
@@ -268,7 +268,7 @@ impl Layout {
268268
#[must_use]
269269
#[inline]
270270
pub const fn dangling_ptr(&self) -> NonNull<u8> {
271-
NonNull::without_provenance(self.align.as_nonzero())
271+
NonNull::without_provenance(self.align.as_nonzero_usize())
272272
}
273273

274274
/// Creates a layout describing the record that can hold a value

0 commit comments

Comments
 (0)