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