File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 1616#![ feature( const_maybe_uninit_as_mut_ptr) ]
1717#![ feature( const_maybe_uninit_assume_init) ]
1818#![ feature( const_maybe_uninit_assume_init_read) ]
19+ #![ feature( const_nonnull_new) ]
1920#![ feature( const_num_from_num) ]
21+ #![ feature( const_ptr_as_ref) ]
2022#![ feature( const_ptr_read) ]
2123#![ feature( const_ptr_write) ]
2224#![ feature( const_ptr_offset) ]
Original file line number Diff line number Diff line change @@ -274,6 +274,21 @@ fn test_unsized_nonnull() {
274274 assert ! ( ys == zs) ;
275275}
276276
277+ #[ test]
278+ fn test_const_nonnull_new ( ) {
279+ const {
280+ assert ! ( NonNull :: new( core:: ptr:: null_mut:: <( ) >( ) ) . is_none( ) ) ;
281+
282+ let value = & mut 0u32 ;
283+ let mut ptr = NonNull :: new ( value) . unwrap ( ) ;
284+ unsafe { * ptr. as_mut ( ) = 42 } ;
285+
286+ let reference = unsafe { & * ptr. as_ref ( ) } ;
287+ assert ! ( * reference == * value) ;
288+ assert ! ( * reference == 42 ) ;
289+ } ;
290+ }
291+
277292#[ test]
278293#[ allow( warnings) ]
279294// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
You can’t perform that action at this time.
0 commit comments