@@ -2244,13 +2244,29 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2244
2244
/// assert_eq!(*v, 42);
2245
2245
/// ```
2246
2246
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2247
+ #[ rustc_const_unstable( feature = "const_ptr_write" , issue = "86302" ) ]
2247
2248
#[ inline]
2248
- pub unsafe fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) {
2249
+ pub const unsafe fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) {
2249
2250
extern "rust-intrinsic" {
2251
+ #[ rustc_const_unstable( feature = "const_ptr_write" , issue = "86302" ) ]
2250
2252
fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) ;
2251
2253
}
2252
2254
2253
- debug_assert ! ( is_aligned_and_not_null( dst) , "attempt to write to unaligned or null pointer" ) ;
2255
+ #[ cfg( debug_assertions) ]
2256
+ fn runtime_check < T > ( ptr : * mut T ) {
2257
+ debug_assert ! (
2258
+ is_aligned_and_not_null( ptr) ,
2259
+ "attempt to write to unaligned or null pointer"
2260
+ ) ;
2261
+ }
2262
+ #[ cfg( debug_assertions) ]
2263
+ const fn compiletime_check < T > ( _ptr : * mut T ) { }
2264
+ #[ cfg( debug_assertions) ]
2265
+ // SAFETY: runtime debug-assertions are a best-effort basis; it's fine to
2266
+ // not do them during compile time
2267
+ unsafe {
2268
+ const_eval_select ( ( dst, ) , compiletime_check, runtime_check) ;
2269
+ }
2254
2270
2255
2271
// SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
2256
2272
unsafe { write_bytes ( dst, val, count) }
0 commit comments