diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 418ca96a2a52..fb8a72ed772b 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -884,6 +884,7 @@ impl *const T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -902,6 +903,7 @@ impl *const T { intrinsics::const_eval_select((this, count, size), comptime, runtime) } + #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, "ptr::add requires that the address calculation does not overflow", @@ -987,6 +989,7 @@ impl *const T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -1004,6 +1007,7 @@ impl *const T { intrinsics::const_eval_select((this, count, size), comptime, runtime) } + #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, "ptr::sub requires that the address calculation does not overflow", diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 8487ba05629f..7a999410d253 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -967,6 +967,7 @@ impl *mut T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -985,6 +986,7 @@ impl *mut T { intrinsics::const_eval_select((this, count, size), comptime, runtime) } + #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, "ptr::add requires that the address calculation does not overflow", @@ -1070,6 +1072,7 @@ impl *mut T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -1087,6 +1090,7 @@ impl *mut T { intrinsics::const_eval_select((this, count, size), comptime, runtime) } + #[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild. ub_checks::assert_unsafe_precondition!( check_language_ub, "ptr::sub requires that the address calculation does not overflow",