Skip to content

Commit 31395ec

Browse files
committed
Auto merge of rust-lang#113687 - saethlin:inline-assertion-helpers, r=cuviper
Add #[inline] to core debug assertion helpers These functions are called a lot and not inlined by default in a dev compiler. Adding `#[inline]` should improve things in a dev workflow and be irrelevant in the distributed library.
2 parents fd56162 + 65e52bb commit 31395ec

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

library/core/src/intrinsics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2524,12 +2524,14 @@ pub(crate) use assert_unsafe_precondition;
25242524

25252525
/// Checks whether `ptr` is properly aligned with respect to
25262526
/// `align_of::<T>()`.
2527+
#[inline]
25272528
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
25282529
!ptr.is_null() && ptr.is_aligned()
25292530
}
25302531

25312532
/// Checks whether an allocation of `len` instances of `T` exceeds
25322533
/// the maximum allowed allocation size.
2534+
#[inline]
25332535
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
25342536
let max_len = const {
25352537
let size = crate::mem::size_of::<T>();
@@ -2540,6 +2542,7 @@ pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
25402542

25412543
/// Checks whether the regions of memory starting at `src` and `dst` of size
25422544
/// `count * size_of::<T>()` do *not* overlap.
2545+
#[inline]
25432546
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
25442547
let src_usize = src.addr();
25452548
let dst_usize = dst.addr();

tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
1010
scope 2 {
1111
scope 3 {
1212
debug result => _0;
13-
scope 7 (inlined std::ptr::write::<u32>) {
13+
scope 6 (inlined std::ptr::write::<u32>) {
1414
debug dst => _1;
1515
debug src => _2;
16-
scope 8 {
17-
scope 9 (inlined std::ptr::write::runtime::<u32>) {
18-
debug dst => _1;
19-
}
16+
scope 7 {
2017
}
2118
}
2219
}
2320
scope 4 (inlined std::ptr::read::<u32>) {
2421
debug src => _1;
2522
scope 5 {
26-
scope 6 (inlined std::ptr::read::runtime::<u32>) {
27-
debug src => _1;
28-
}
2923
}
3024
}
3125
}

0 commit comments

Comments
 (0)