File tree Expand file tree Collapse file tree 4 files changed +13
-22
lines changed Expand file tree Collapse file tree 4 files changed +13
-22
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,14 @@ impl Closure {
116116/// C1.call(); 
117117/// C2.call(); 
118118/// ``` 
119+ /// 
120+ /// Don't call it at runtime: 
121+ /// 
122+ /// ```rust,should_panic 
123+ /// use r3_core::closure::Closure; 
124+ /// let x = [1, 2, 3]; 
125+ /// Closure::from_fn_const(move || { let _x = x; }); 
126+ /// ``` 
119127pub  const  fn  from_fn_const < T :  FnOnce ( )  + Copy  + Send  + ' static > ( func :  T )  -> Self  { 
120128        let  size = size_of :: < T > ( ) ; 
121129        let  align = align_of :: < T > ( ) ; 
@@ -128,6 +136,10 @@ impl Closure {
128136                Self :: from_raw_parts ( trampoline_zst :: < T > ,  ClosureEnv ( None ) ) 
129137            }  else  { 
130138                let  env = core:: intrinsics:: const_allocate ( size,  align) ; 
139+                 assert ! ( 
140+                     !env. guaranteed_eq( core:: ptr:: null_mut( ) ) , 
141+                     "heap allocation failed" 
142+                 ) ; 
131143                env. cast :: < T > ( ) . write ( func) ; 
132144                Self :: from_raw_parts ( trampoline_indirect :: < T > ,  transmute ( env) ) 
133145            } 
Original file line number Diff line number Diff line change 1313#![ feature( const_raw_ptr_comparison) ]  
1414#![ feature( const_ptr_offset_from) ]  
1515#![ feature( maybe_uninit_slice) ]  
16- #![ feature( const_eval_select) ]  
1716#![ feature( const_mut_refs) ]  
1817#![ feature( const_slice_from_raw_parts) ]  
1918#![ feature( const_option) ]  
Original file line number Diff line number Diff line change @@ -462,17 +462,7 @@ unsafe impl const rlsf::FlexSource for ConstFlexSource {
462462
463463        assert ! ( min_size != 0 ) ; 
464464
465-         // FIXME: Directly calling `const_allocate` from here causes the 
466-         //        compiler to panic 
467-         // Safety: `const_allocate_{in_const, at_rt}` behave observably 
468-         //         equivalent... if their results are ever observed. 
469-         let  ptr = unsafe  { 
470-             core:: intrinsics:: const_eval_select ( 
471-                 ( size,  BLOCK_SIZE ) , 
472-                 const_allocate_in_const, 
473-                 const_allocate_at_rt, 
474-             ) 
475-         } ; 
465+         let  ptr = unsafe  {  core:: intrinsics:: const_allocate ( size,  BLOCK_SIZE )  } ; 
476466
477467        // FIXME: `NonNull::new` is not `const fn` yet 
478468        assert ! ( !ptr. guaranteed_eq( core:: ptr:: null_mut( ) ) ) ; 
@@ -485,12 +475,3 @@ unsafe impl const rlsf::FlexSource for ConstFlexSource {
485475        BLOCK_SIZE 
486476    } 
487477} 
488- 
489- const  fn  const_allocate_in_const ( size :  usize ,  align :  usize )  -> * mut  u8  { 
490-     // Safety: Technically it's not `unsafe` 
491-     unsafe  {  core:: intrinsics:: const_allocate ( size,  align)  } 
492- } 
493- 
494- fn  const_allocate_at_rt ( _:  usize ,  _:  usize )  -> * mut  u8  { 
495-     loop  { } 
496- } 
Original file line number Diff line number Diff line change 1010#![ feature( generic_const_exprs) ]  
1111#![ feature( const_refs_to_cell) ]  
1212#![ feature( maybe_uninit_slice) ]  
13- #![ feature( const_eval_select) ]  
1413#![ feature( const_option_ext) ]  
1514#![ feature( const_ptr_as_ref) ]  
1615#![ feature( const_ptr_offset) ]  
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments