File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed
Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -1914,12 +1914,13 @@ extern "rust-intrinsic" {
19141914 #[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
19151915 pub fn ptr_guaranteed_ne < T > ( ptr : * const T , other : * const T ) -> bool ;
19161916
1917- /// Allocate at compile time. Should not be called at runtime.
1917+ /// Allocate at compile time.
1918+ /// Returns a null pointer at runtime.
19181919 #[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
19191920 pub fn const_allocate ( size : usize , align : usize ) -> * mut u8 ;
19201921
19211922 /// Deallocate a memory which allocated by `intrinsics::const_allocate` at compile time.
1922- /// Should not be called at runtime.
1923+ /// Does nothing at runtime.
19231924 #[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
19241925 #[ cfg( not( bootstrap) ) ]
19251926 pub fn const_deallocate ( ptr : * mut u8 , size : usize , align : usize ) ;
Original file line number Diff line number Diff line change @@ -80,3 +80,16 @@ fn test_hints_in_const_contexts() {
8080 assert ! ( 42u32 == core:: hint:: black_box( 42u32 ) ) ;
8181 }
8282}
83+
84+ #[ cfg( not( bootstrap) ) ]
85+ #[ test]
86+ fn test_const_dealocate_at_runtime ( ) {
87+ use core:: intrinsics:: const_deallocate;
88+ const X : & u32 = & 42u32 ;
89+ let x = & 0u32 ;
90+ unsafe {
91+ const_deallocate ( X as * const _ as * mut u8 , 4 , 4 ) ; // nop
92+ const_deallocate ( x as * const _ as * mut u8 , 4 , 4 ) ; // nop
93+ const_deallocate ( core:: ptr:: null_mut ( ) , 1 , 1 ) ; // nop
94+ }
95+ }
Original file line number Diff line number Diff line change 1313#![ feature( const_bool_to_option) ]
1414#![ feature( const_cell_into_inner) ]
1515#![ feature( const_convert) ]
16+ #![ feature( const_heap) ]
1617#![ feature( const_maybe_uninit_as_mut_ptr) ]
1718#![ feature( const_maybe_uninit_assume_init) ]
1819#![ feature( const_maybe_uninit_assume_init_read) ]
You can’t perform that action at this time.
0 commit comments