File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1069,8 +1069,9 @@ impl<T: ?Sized> *mut T {
10691069 ///
10701070 /// [`ptr::write_bytes`]: crate::ptr::write_bytes()
10711071 #[ stable( feature = "pointer_methods" , since = "1.26.0" ) ]
1072+ #[ rustc_const_unstable( feature = "const_ptr_write" , issue = "86302" ) ]
10721073 #[ inline( always) ]
1073- pub unsafe fn write_bytes ( self , val : u8 , count : usize )
1074+ pub const unsafe fn write_bytes ( self , val : u8 , count : usize )
10741075 where
10751076 T : Sized ,
10761077 {
Original file line number Diff line number Diff line change @@ -250,6 +250,21 @@ fn test_set_memory() {
250250 assert ! ( xs == [ 5u8 ; 20 ] ) ;
251251}
252252
253+ #[ test]
254+ #[ cfg( not( bootstrap) ) ]
255+ fn test_set_memory_const ( ) {
256+ const XS : [ u8 ; 20 ] = {
257+ let mut xs = [ 0u8 ; 20 ] ;
258+ let ptr = xs. as_mut_ptr ( ) ;
259+ unsafe {
260+ ptr. write_bytes ( 5u8 , xs. len ( ) ) ;
261+ }
262+ xs
263+ } ;
264+
265+ assert ! ( XS == [ 5u8 ; 20 ] ) ;
266+ }
267+
253268#[ test]
254269fn test_unsized_nonnull ( ) {
255270 let xs: & [ i32 ] = & [ 1 , 2 , 3 ] ;
You can’t perform that action at this time.
0 commit comments