Skip to content

Commit 4da8687

Browse files
Rollup merge of rust-lang#123168 - joshtriplett:size-of-prelude, r=Amanieu
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude (Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.) Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it.
2 parents 435f706 + 3927f4a commit 4da8687

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

crates/core_simd/src/simd/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
fn cast<U>(self) -> Self::CastPtr<U> {
9797
// SimdElement currently requires zero-sized metadata, so this should never fail.
9898
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
99-
use core::{mem::size_of, ptr::Pointee};
99+
use core::ptr::Pointee;
100100
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
101101
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);
102102

crates/core_simd/src/simd/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
fn cast<U>(self) -> Self::CastPtr<U> {
9494
// SimdElement currently requires zero-sized metadata, so this should never fail.
9595
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
96-
use core::{mem::size_of, ptr::Pointee};
96+
use core::ptr::Pointee;
9797
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
9898
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);
9999

0 commit comments

Comments
 (0)