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" {
1914
1914
#[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
1915
1915
pub fn ptr_guaranteed_ne < T > ( ptr : * const T , other : * const T ) -> bool ;
1916
1916
1917
- /// Allocate at compile time. Should not be called at runtime.
1917
+ /// Allocate at compile time.
1918
+ /// Returns a null pointer at runtime.
1918
1919
#[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
1919
1920
pub fn const_allocate ( size : usize , align : usize ) -> * mut u8 ;
1920
1921
1921
1922
/// Deallocate a memory which allocated by `intrinsics::const_allocate` at compile time.
1922
- /// Should not be called at runtime.
1923
+ /// Does nothing at runtime.
1923
1924
#[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
1924
1925
#[ cfg( not( bootstrap) ) ]
1925
1926
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() {
80
80
assert ! ( 42u32 == core:: hint:: black_box( 42u32 ) ) ;
81
81
}
82
82
}
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 13
13
#![ feature( const_bool_to_option) ]
14
14
#![ feature( const_cell_into_inner) ]
15
15
#![ feature( const_convert) ]
16
+ #![ feature( const_heap) ]
16
17
#![ feature( const_maybe_uninit_as_mut_ptr) ]
17
18
#![ feature( const_maybe_uninit_assume_init) ]
18
19
#![ feature( const_maybe_uninit_assume_init_read) ]
You can’t perform that action at this time.
0 commit comments