Skip to content

Commit 7fff787

Browse files
committed
Auto merge of rust-lang#147793 - cjgillot:no-null-op, r=scottmcm,oli-obk
Replace NullOp::SizeOf and NullOp::AlignOf by lang items. Part of rust-lang#146411 Fixes rust-lang#119729 Keeps rust-lang#136175 as it involves `offset_of!` which this PR does not touch. r? `@ghost`
2 parents f140393 + 6166628 commit 7fff787

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

core/src/mem/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
333333
#[rustc_const_stable(feature = "const_mem_size_of", since = "1.24.0")]
334334
#[rustc_diagnostic_item = "mem_size_of"]
335335
pub const fn size_of<T>() -> usize {
336-
intrinsics::size_of::<T>()
336+
<T as SizedTypeProperties>::SIZE
337337
}
338338

339339
/// Returns the size of the pointed-to value in bytes.
@@ -441,7 +441,7 @@ pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
441441
#[stable(feature = "rust1", since = "1.0.0")]
442442
#[deprecated(note = "use `align_of` instead", since = "1.2.0", suggestion = "align_of")]
443443
pub fn min_align_of<T>() -> usize {
444-
intrinsics::align_of::<T>()
444+
<T as SizedTypeProperties>::ALIGN
445445
}
446446

447447
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@@ -488,7 +488,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
488488
#[rustc_const_stable(feature = "const_align_of", since = "1.24.0")]
489489
#[rustc_diagnostic_item = "mem_align_of"]
490490
pub const fn align_of<T>() -> usize {
491-
intrinsics::align_of::<T>()
491+
<T as SizedTypeProperties>::ALIGN
492492
}
493493

494494
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@@ -1236,6 +1236,16 @@ pub const fn variant_count<T>() -> usize {
12361236
#[doc(hidden)]
12371237
#[unstable(feature = "sized_type_properties", issue = "none")]
12381238
pub trait SizedTypeProperties: Sized {
1239+
#[doc(hidden)]
1240+
#[unstable(feature = "sized_type_properties", issue = "none")]
1241+
#[lang = "mem_size_const"]
1242+
const SIZE: usize = intrinsics::size_of::<Self>();
1243+
1244+
#[doc(hidden)]
1245+
#[unstable(feature = "sized_type_properties", issue = "none")]
1246+
#[lang = "mem_align_const"]
1247+
const ALIGN: usize = intrinsics::align_of::<Self>();
1248+
12391249
/// `true` if this type requires no storage.
12401250
/// `false` if its [size](size_of) is greater than zero.
12411251
///
@@ -1263,7 +1273,7 @@ pub trait SizedTypeProperties: Sized {
12631273
/// ```
12641274
#[doc(hidden)]
12651275
#[unstable(feature = "sized_type_properties", issue = "none")]
1266-
const IS_ZST: bool = size_of::<Self>() == 0;
1276+
const IS_ZST: bool = Self::SIZE == 0;
12671277

12681278
#[doc(hidden)]
12691279
#[unstable(feature = "sized_type_properties", issue = "none")]
@@ -1275,7 +1285,7 @@ pub trait SizedTypeProperties: Sized {
12751285
/// which is never allowed for a single object.
12761286
#[doc(hidden)]
12771287
#[unstable(feature = "sized_type_properties", issue = "none")]
1278-
const MAX_SLICE_LEN: usize = match size_of::<Self>() {
1288+
const MAX_SLICE_LEN: usize = match Self::SIZE {
12791289
0 => usize::MAX,
12801290
n => (isize::MAX as usize) / n,
12811291
};

0 commit comments

Comments
 (0)