Skip to content

Commit b139e21

Browse files
authored
Merge pull request #19288 from thaliaarchi/use-prelude-size-of
Use `size_of` from the prelude instead of imported
2 parents 4815ab0 + 0811ca0 commit b139e21

File tree

12 files changed

+30
-34
lines changed

12 files changed

+30
-34
lines changed

crates/hir-def/src/hir/type_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub enum TypeBound {
260260
}
261261

262262
#[cfg(target_pointer_width = "64")]
263-
const _: [(); 24] = [(); ::std::mem::size_of::<TypeBound>()];
263+
const _: [(); 24] = [(); size_of::<TypeBound>()];
264264

265265
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
266266
pub enum UseArgRef {

crates/hir-ty/src/consteval/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2713,12 +2713,11 @@ fn const_trait_assoc() {
27132713
r#"
27142714
//- minicore: size_of, fn
27152715
//- /a/lib.rs crate:a
2716-
use core::mem::size_of;
27172716
pub struct S<T>(T);
27182717
impl<T> S<T> {
27192718
pub const X: usize = {
27202719
let k: T;
2721-
let f = || core::mem::size_of::<T>();
2720+
let f = || size_of::<T>();
27222721
f()
27232722
};
27242723
}

crates/hir-ty/src/display.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use std::{
66
fmt::{self, Debug},
7-
mem::{self, size_of},
7+
mem,
88
};
99

1010
use base_db::CrateId;

crates/hir-ty/src/mir/eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl Address {
302302
}
303303
}
304304

305-
fn to_bytes(&self) -> [u8; mem::size_of::<usize>()] {
305+
fn to_bytes(&self) -> [u8; size_of::<usize>()] {
306306
usize::to_le_bytes(self.to_usize())
307307
}
308308

@@ -589,7 +589,7 @@ pub fn interpret_mir(
589589
let ty = body.locals[return_slot()].ty.clone();
590590
let mut evaluator = Evaluator::new(db, body.owner, assert_placeholder_ty_is_unused, trait_env)?;
591591
let it: Result<Const> = (|| {
592-
if evaluator.ptr_size() != std::mem::size_of::<usize>() {
592+
if evaluator.ptr_size() != size_of::<usize>() {
593593
not_supported!("targets with different pointer size from host");
594594
}
595595
let interval = evaluator.interpret_mir(body.clone(), None.into_iter())?;

crates/hir-ty/src/mir/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
13941394
.layout_of_ty(ty.clone(), self.db.trait_environment_for_body(self.owner))
13951395
.map(|it| it.size.bytes_usize())
13961396
};
1397-
const USIZE_SIZE: usize = mem::size_of::<usize>();
1397+
const USIZE_SIZE: usize = size_of::<usize>();
13981398
let bytes: Box<[_]> = match l {
13991399
hir_def::hir::Literal::String(b) => {
14001400
let b = b.as_str();

crates/ide-completion/src/tests/expression.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,7 @@ fn bar() {
19201920
md rust_2015 (use core::prelude::rust_2015)
19211921
md rust_2018 (use core::prelude::rust_2018)
19221922
md rust_2021 (use core::prelude::rust_2021)
1923+
md rust_2024 (use core::prelude::rust_2024)
19231924
tt Clone
19241925
tt Copy
19251926
tt IntoIterator

crates/ide-db/src/generated/lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15086,7 +15086,7 @@ cannot be represented as the underlying type without loss."##,
1508615086
},
1508715087
Lint {
1508815088
label: "clippy::manual_bits",
15089-
description: r##"Checks for usage of `std::mem::size_of::<T>() * 8` when
15089+
description: r##"Checks for usage of `size_of::<T>() * 8` when
1509015090
`T::BITS` is available."##,
1509115091
default_severity: Severity::Allow,
1509215092
warn_since: None,
@@ -17428,7 +17428,7 @@ count of elements of type `T`"##,
1742817428
},
1742917429
Lint {
1743017430
label: "clippy::size_of_ref",
17431-
description: r##"Checks for calls to `std::mem::size_of_val()` where the argument is
17431+
description: r##"Checks for calls to `size_of_val()` where the argument is
1743217432
a reference to a reference."##,
1743317433
default_severity: Severity::Allow,
1743417434
warn_since: None,

crates/ide-db/src/symbol_index.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use std::{
2424
cmp::Ordering,
2525
fmt,
2626
hash::{Hash, Hasher},
27-
mem,
2827
ops::ControlFlow,
2928
};
3029

@@ -299,7 +298,7 @@ impl SymbolIndex {
299298
}
300299

301300
pub fn memory_size(&self) -> usize {
302-
self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>()
301+
self.map.as_fst().size() + self.symbols.len() * size_of::<FileSymbol>()
303302
}
304303

305304
fn range_to_map_value(start: usize, end: usize) -> u64 {

crates/ide/src/status.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ struct AttrsStats {
268268

269269
impl fmt::Display for AttrsStats {
270270
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
271-
let size =
272-
self.entries * std::mem::size_of::<Attrs>() + self.total * std::mem::size_of::<Attr>();
271+
let size = self.entries * size_of::<Attrs>() + self.total * size_of::<Attr>();
273272
let size = Bytes::new(size as _);
274273
write!(
275274
fmt,

crates/intern/src/symbol.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@ use triomphe::Arc;
1818
pub mod symbols;
1919

2020
// some asserts for layout compatibility
21-
const _: () = assert!(std::mem::size_of::<Box<str>>() == std::mem::size_of::<&str>());
22-
const _: () = assert!(std::mem::align_of::<Box<str>>() == std::mem::align_of::<&str>());
21+
const _: () = assert!(size_of::<Box<str>>() == size_of::<&str>());
22+
const _: () = assert!(align_of::<Box<str>>() == align_of::<&str>());
2323

24-
const _: () = assert!(std::mem::size_of::<Arc<Box<str>>>() == std::mem::size_of::<&&str>());
25-
const _: () = assert!(std::mem::align_of::<Arc<Box<str>>>() == std::mem::align_of::<&&str>());
24+
const _: () = assert!(size_of::<Arc<Box<str>>>() == size_of::<&&str>());
25+
const _: () = assert!(align_of::<Arc<Box<str>>>() == align_of::<&&str>());
2626

27-
const _: () =
28-
assert!(std::mem::size_of::<*const *const str>() == std::mem::size_of::<TaggedArcPtr>());
29-
const _: () =
30-
assert!(std::mem::align_of::<*const *const str>() == std::mem::align_of::<TaggedArcPtr>());
27+
const _: () = assert!(size_of::<*const *const str>() == size_of::<TaggedArcPtr>());
28+
const _: () = assert!(align_of::<*const *const str>() == align_of::<TaggedArcPtr>());
3129

32-
const _: () = assert!(std::mem::size_of::<Arc<Box<str>>>() == std::mem::size_of::<TaggedArcPtr>());
33-
const _: () =
34-
assert!(std::mem::align_of::<Arc<Box<str>>>() == std::mem::align_of::<TaggedArcPtr>());
30+
const _: () = assert!(size_of::<Arc<Box<str>>>() == size_of::<TaggedArcPtr>());
31+
const _: () = assert!(align_of::<Arc<Box<str>>>() == align_of::<TaggedArcPtr>());
3532

3633
/// A pointer that points to a pointer to a `str`, it may be backed as a `&'static &'static str` or
3734
/// `Arc<Box<str>>` but its size is that of a thin pointer. The active variant is encoded as a tag
@@ -49,9 +46,7 @@ impl TaggedArcPtr {
4946
const BOOL_BITS: usize = true as usize;
5047

5148
const fn non_arc(r: &'static &'static str) -> Self {
52-
assert!(
53-
mem::align_of::<&'static &'static str>().trailing_zeros() as usize > Self::BOOL_BITS
54-
);
49+
assert!(align_of::<&'static &'static str>().trailing_zeros() as usize > Self::BOOL_BITS);
5550
// SAFETY: The pointer is non-null as it is derived from a reference
5651
// Ideally we would call out to `pack_arc` but for a `false` tag, unfortunately the
5752
// packing stuff requires reading out the pointer to an integer which is not supported
@@ -64,9 +59,7 @@ impl TaggedArcPtr {
6459
}
6560

6661
fn arc(arc: Arc<Box<str>>) -> Self {
67-
assert!(
68-
mem::align_of::<&'static &'static str>().trailing_zeros() as usize > Self::BOOL_BITS
69-
);
62+
assert!(align_of::<&'static &'static str>().trailing_zeros() as usize > Self::BOOL_BITS);
7063
Self {
7164
packed: Self::pack_arc(
7265
// Safety: `Arc::into_raw` always returns a non null pointer
@@ -131,8 +124,8 @@ impl fmt::Debug for Symbol {
131124
}
132125
}
133126

134-
const _: () = assert!(std::mem::size_of::<Symbol>() == std::mem::size_of::<NonNull<()>>());
135-
const _: () = assert!(std::mem::align_of::<Symbol>() == std::mem::align_of::<NonNull<()>>());
127+
const _: () = assert!(size_of::<Symbol>() == size_of::<NonNull<()>>());
128+
const _: () = assert!(align_of::<Symbol>() == align_of::<NonNull<()>>());
136129

137130
static MAP: OnceLock<DashMap<SymbolProxy, (), BuildHasherDefault<FxHasher>>> = OnceLock::new();
138131

crates/profile/src/memory_usage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl MemoryUsage {
3838
// approximate that by using the Commit Charge value.
3939

4040
use windows_sys::Win32::System::{Threading::*, ProcessStatus::*};
41-
use std::mem::{MaybeUninit, size_of};
41+
use std::mem::MaybeUninit;
4242

4343
let proc = unsafe { GetCurrentProcess() };
4444
let mut mem_counters = MaybeUninit::uninit();

crates/test-utils/src/minicore.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ macro_rules! impl_int {
18251825
($($t:ty)*) => {
18261826
$(
18271827
impl $t {
1828-
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
1828+
pub const fn from_ne_bytes(bytes: [u8; size_of::<Self>()]) -> Self {
18291829
unsafe { mem::transmute(bytes) }
18301830
}
18311831
}
@@ -1874,6 +1874,7 @@ pub mod prelude {
18741874
marker::Sized, // :sized
18751875
marker::Sync, // :sync
18761876
mem::drop, // :drop
1877+
mem::size_of, // :size_of
18771878
ops::Drop, // :drop
18781879
ops::{AsyncFn, AsyncFnMut, AsyncFnOnce}, // :async_fn
18791880
ops::{Fn, FnMut, FnOnce}, // :fn
@@ -1895,6 +1896,10 @@ pub mod prelude {
18951896
pub mod rust_2021 {
18961897
pub use super::v1::*;
18971898
}
1899+
1900+
pub mod rust_2024 {
1901+
pub use super::v1::*;
1902+
}
18981903
}
18991904

19001905
#[prelude_import]

0 commit comments

Comments
 (0)