From 27379ac7161269505eb2057d1db852a2227278d7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 11 Apr 2024 10:41:35 +0200 Subject: [PATCH] USIZE_MARKER: make sure the function is monomorphized only once --- library/core/src/fmt/rt.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index 5bf221b429fac..15a40e6e4806d 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -209,8 +209,15 @@ extern "C" { // first argument. The read_volatile here ensures that we can safely ready out a // usize from the passed reference and that this address does not point at a // non-usize taking function. -static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = |ptr, _| { - // SAFETY: ptr is a reference - let _v: usize = unsafe { crate::ptr::read_volatile(ptr) }; - loop {} +static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = { + // Make sure this function is only monomorphized once, and not considered cross-crate + // inlineable. + #[inline(never)] + fn usize_marker(ptr: &usize, _: &mut Formatter<'_>) -> Result { + // SAFETY: ptr is a reference + let _v: usize = unsafe { crate::ptr::read_volatile(ptr) }; + loop {} + } + + usize_marker };