diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 9ee61f97c91e8..067457e235bf1 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2575,6 +2575,7 @@ pub const fn is_val_statically_known(_arg: T) -> bool { /// assertions disabled. This intrinsic is primarily used by [`assert_unsafe_precondition`]. #[rustc_const_unstable(feature = "delayed_debug_assertions", issue = "none")] #[unstable(feature = "core_intrinsics", issue = "none")] +#[inline(always)] #[cfg_attr(not(bootstrap), rustc_intrinsic)] pub(crate) const fn debug_assertions() -> bool { cfg!(debug_assertions) @@ -2659,7 +2660,13 @@ pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) macro_rules! assert_unsafe_precondition { ($message:expr, ($($name:ident:$ty:ty = $arg:expr),*$(,)?) => $e:expr $(,)?) => { { - #[inline(never)] + // When the standard library is compiled with debug assertions, we want the check to inline for better performance. + // This is important when working on the compiler, which is compiled with debug assertions locally. + // When not compiled with debug assertions (so the precompiled std) we outline the check to minimize the compile + // time impact when debug assertions are disabled. + // It is not clear whether that is the best solution, see #120848. + #[cfg_attr(debug_assertions, inline(always))] + #[cfg_attr(not(debug_assertions), inline(never))] #[rustc_nounwind] fn precondition_check($($name:$ty),*) { if !$e {