File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed 
compiler/rustc_thread_pool/src Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -388,13 +388,16 @@ impl Latch for CountLatch {
388388    #[ inline]  
389389    unsafe  fn  set ( this :  * const  Self )  { 
390390        if  unsafe  {  ( * this) . counter . fetch_sub ( 1 ,  Ordering :: SeqCst )  == 1  }  { 
391-             // NOTE : Once we call `set` on the internal `latch`, 
391+             // SAFETY : Once we call `set` on the internal `latch`, 
392392            // the target may proceed and invalidate `this`! 
393393            match  unsafe  {  & ( * this) . kind  }  { 
394394                CountLatchKind :: Stealing  {  latch,  registry,  worker_index }  => { 
395395                    let  registry = Arc :: clone ( registry) ; 
396+                     let  worker_index = * worker_index; 
396397                    if  unsafe  {  CoreLatch :: set ( latch)  }  { 
397-                         registry. notify_worker_latch_is_set ( * worker_index) ; 
398+                         // We **must not** access any part of `this` anymore, 
399+                         // which is why we read the fields beforehand. 
400+                         registry. notify_worker_latch_is_set ( worker_index) ; 
398401                    } 
399402                } 
400403                CountLatchKind :: Blocking  {  latch }  => unsafe  {  LockLatch :: set ( latch)  } , 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments