File tree 2 files changed +17
-1
lines changed
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 {
1069
1069
///
1070
1070
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
1071
1071
#[ stable( feature = "pointer_methods" , since = "1.26.0" ) ]
1072
+ #[ rustc_const_unstable( feature = "const_ptr_write" , issue = "86302" ) ]
1072
1073
#[ 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 )
1074
1075
where
1075
1076
T : Sized ,
1076
1077
{
Original file line number Diff line number Diff line change @@ -250,6 +250,21 @@ fn test_set_memory() {
250
250
assert ! ( xs == [ 5u8 ; 20 ] ) ;
251
251
}
252
252
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
+
253
268
#[ test]
254
269
fn test_unsized_nonnull ( ) {
255
270
let xs: & [ i32 ] = & [ 1 , 2 , 3 ] ;
You can’t perform that action at this time.
0 commit comments