Skip to content

Commit c6020bf

Browse files
committed
Auto merge of rust-lang#138157 - scottmcm:inline-more-tiny-things, r=oli-obk
Allow more top-down inlining for single-BB callees This means that things like `<usize as Step>::forward_unchecked` and `<PartialOrd for f32>::le` will inline even if we've already done a bunch of inlining to find the calls to them. Fixes rust-lang#138136 ~~Draft as it's built atop rust-lang#138135, which adds a mir-opt test that's a nice demonstration of this. To see just this change, look at <https://github.com/rust-lang/rust/pull/138157/commits/48f63e3be552605c2933056b77bf23a326757f92>~~ Rebased to be just the inlining change, as the other existing tests show it great.
2 parents bf96539 + 983420c commit c6020bf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

core/src/mem/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,13 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
856856
// such that the old value is not duplicated. Nothing is dropped and
857857
// nothing here can panic.
858858
unsafe {
859-
let result = ptr::read(dest);
860-
ptr::write(dest, src);
859+
// Ideally we wouldn't use the intrinsics here, but going through the
860+
// `ptr` methods introduces two unnecessary UbChecks, so until we can
861+
// remove those for pointers that come from references, this uses the
862+
// intrinsics instead so this stays very cheap in MIR (and debug).
863+
864+
let result = crate::intrinsics::read_via_copy(dest);
865+
crate::intrinsics::write_via_move(dest, src);
861866
result
862867
}
863868
}

0 commit comments

Comments
 (0)