File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1583,6 +1583,7 @@ symbols! {
15831583        unrestricted_attribute_tokens, 
15841584        unsafe_block_in_unsafe_fn, 
15851585        unsafe_cell, 
1586+         unsafe_cell_from_mut, 
15861587        unsafe_no_drop_flag, 
15871588        unsafe_pin_internals, 
15881589        unsize, 
Original file line number Diff line number Diff line change @@ -2030,6 +2030,27 @@ impl<T> UnsafeCell<T> {
20302030} 
20312031
20322032impl < T :  ?Sized >  UnsafeCell < T >  { 
2033+     /// Converts from `&mut T` to `&mut UnsafeCell<T>`. 
2034+      /// 
2035+      /// # Examples 
2036+      /// 
2037+      /// ``` 
2038+      /// # #![feature(unsafe_cell_from_mut)] 
2039+      /// use std::cell::UnsafeCell; 
2040+      /// 
2041+      /// let mut val = 42; 
2042+      /// let uc = UnsafeCell::from_mut(&mut val); 
2043+      /// 
2044+      /// *uc.get_mut() -= 1; 
2045+      /// assert_eq!(*uc.get_mut(), 41); 
2046+      /// ``` 
2047+      #[ inline( always) ]  
2048+     #[ unstable( feature = "unsafe_cell_from_mut" ,  issue = "111645" ) ]  
2049+     pub  const  fn  from_mut ( value :  & mut  T )  -> & mut  UnsafeCell < T >  { 
2050+         // SAFETY: `UnsafeCell<T>` has the same memory layout as `T` due to #[repr(transparent)]. 
2051+         unsafe  {  & mut  * ( value as  * mut  T  as  * mut  UnsafeCell < T > )  } 
2052+     } 
2053+ 
20332054    /// Gets a mutable pointer to the wrapped value. 
20342055     /// 
20352056     /// This can be cast to a pointer of any kind. 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments