@@ -309,16 +309,16 @@ impl MutableBody {
309309                // Update the source to point at the terminator. 
310310                * source = SourceInstruction :: Terminator  {  bb :  orig_bb } ; 
311311            } 
312-             // Make the terminator at `source` point at the new block, 
313-             // the terminator of which is a simple Goto instruction . 
312+             // Make the terminator at `source` point at the new block, the terminator of which is  
313+             // provided by the caller . 
314314            SourceInstruction :: Terminator  {  bb }  => { 
315315                let  current_term = & mut  self . blocks . get_mut ( * bb) . unwrap ( ) . terminator ; 
316316                let  target_bb = get_mut_target_ref ( current_term) ; 
317317                let  new_target_bb = get_mut_target_ref ( & mut  new_term) ; 
318-                 // Set  the new terminator to point where previous  terminator pointed.  
319-                 * new_target_bb =  * target_bb ; 
320-                 // Point the current terminator to the  new terminator's basic block . 
321-                 * target_bb = new_bb_idx ; 
318+                 // Swap  the targets of the newly inserted  terminator and the original one. This is  
319+                 // an easy way to make the original terminator point to the new basic block with the 
320+                 // new terminator. 
321+                 std :: mem :: swap ( new_target_bb ,  target_bb ) ; 
322322                // Update the source to point at the terminator. 
323323                * bb = new_bb_idx; 
324324                self . blocks . push ( BasicBlock  {  statements :  vec ! [ ] ,  terminator :  new_term } ) ; 
@@ -501,6 +501,10 @@ impl SourceInstruction {
501501            SourceInstruction :: Statement  {  bb,  .. }  | SourceInstruction :: Terminator  {  bb }  => bb, 
502502        } 
503503    } 
504+ 
505+     pub  fn  is_terminator ( & self )  -> bool  { 
506+         matches ! ( self ,  SourceInstruction :: Terminator  {  .. } ) 
507+     } 
504508} 
505509
506510fn  find_instance ( tcx :  TyCtxt ,  diagnostic :  & str )  -> Option < Instance >  { 
0 commit comments