Skip to content

Commit f8d658a

Browse files
committed
core: move Alignment from ptr to mem
1 parent 8a70352 commit f8d658a

40 files changed

Lines changed: 102 additions & 90 deletions

File tree

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_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
@@ -1224,6 +1224,7 @@ symbols! {
12241224
maybe_uninit,
12251225
maybe_uninit_uninit,
12261226
maybe_uninit_zeroed,
1227+
mem,
12271228
mem_align_const,
12281229
mem_discriminant,
12291230
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: 2 additions & 2 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))]

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: 2 additions & 2 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.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Alignment {
3737
///
3838
/// ```
3939
/// #![feature(ptr_alignment_type)]
40-
/// use std::ptr::Alignment;
40+
/// use std::mem::Alignment;
4141
///
4242
/// assert_eq!(Alignment::MIN.as_usize(), 1);
4343
/// ```
@@ -65,7 +65,7 @@ impl Alignment {
6565
///
6666
/// ```
6767
/// #![feature(ptr_alignment_type)]
68-
/// use std::ptr::Alignment;
68+
/// use std::mem::Alignment;
6969
///
7070
/// assert_eq!(Alignment::of_val(&5i32).as_usize(), 4);
7171
/// ```
@@ -112,14 +112,13 @@ impl Alignment {
112112
///
113113
/// ```
114114
/// #![feature(ptr_alignment_type)]
115-
/// use std::ptr::Alignment;
115+
/// use std::mem::Alignment;
116116
///
117117
/// assert_eq!(unsafe { Alignment::of_val_raw(&5i32) }.as_usize(), 4);
118118
/// ```
119119
#[inline]
120120
#[must_use]
121121
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
122-
// #[unstable(feature = "layout_for_ptr", issue = "69835")]
123122
pub const unsafe fn of_val_raw<T: MetaSized>(val: *const T) -> Self {
124123
// SAFETY: precondition propagated to the caller
125124
let align = unsafe { mem::align_of_val_raw(val) };
@@ -214,9 +213,10 @@ impl Alignment {
214213
/// # Examples
215214
///
216215
/// ```
217-
/// #![feature(ptr_alignment_type)]
218216
/// #![feature(ptr_mask)]
219-
/// use std::ptr::{Alignment, NonNull};
217+
/// #![feature(ptr_alignment_type)]
218+
/// use std::mem::Alignment;
219+
/// use std::ptr::NonNull;
220220
///
221221
/// #[repr(align(1))] struct Align1(u8);
222222
/// #[repr(align(2))] struct Align2(u16);
@@ -294,7 +294,7 @@ impl const From<Alignment> for usize {
294294
impl cmp::Ord for Alignment {
295295
#[inline]
296296
fn cmp(&self, other: &Self) -> cmp::Ordering {
297-
self.as_nonzero().get().cmp(&other.as_nonzero().get())
297+
self.as_nonzero().cmp(&other.as_nonzero())
298298
}
299299
}
300300

0 commit comments

Comments
 (0)