@@ -302,6 +302,7 @@ fn compute_replacement<'tcx>(
302302    return  Replacer  { 
303303        tcx, 
304304        targets :  finder. targets , 
305+         remap_var_debug_infos :  IndexVec :: from_elem ( None ,  body. local_decls ( ) ) , 
305306        storage_to_remove, 
306307        allowed_replacements, 
307308        any_replacement :  false , 
@@ -381,6 +382,7 @@ fn fully_replaceable_locals(ssa: &SsaLocals) -> DenseBitSet<Local> {
381382struct  Replacer < ' tcx >  { 
382383    tcx :  TyCtxt < ' tcx > , 
383384    targets :  IndexVec < Local ,  Value < ' tcx > > , 
385+     remap_var_debug_infos :  IndexVec < Local ,  Option < Local > > , 
384386    storage_to_remove :  DenseBitSet < Local > , 
385387    allowed_replacements :  FxHashSet < ( Local ,  Location ) > , 
386388    any_replacement :  bool , 
@@ -392,21 +394,45 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
392394    } 
393395
394396    fn  visit_var_debug_info ( & mut  self ,  debuginfo :  & mut  VarDebugInfo < ' tcx > )  { 
395-         // If the debuginfo is a pointer to another place 
396-         // and it's a reborrow: see through it 
397-         while  let  VarDebugInfoContents :: Place ( ref  mut  place)  = debuginfo. value 
397+         if  let  VarDebugInfoContents :: Place ( ref  mut  place)  = debuginfo. value 
398398            && place. projection . is_empty ( ) 
399-             && let  Value :: Pointer ( target,  _)  = self . targets [ place. local ] 
400-             && let  & [ PlaceElem :: Deref ]  = & target. projection [ ..] 
401399        { 
402-             * place = Place :: from ( target. local ) ; 
403-             self . any_replacement  = true ; 
400+             let  mut  new_local = place. local ; 
401+ 
402+             // If the debuginfo is a pointer to another place 
403+             // and it's a reborrow: see through it 
404+             while  let  Value :: Pointer ( target,  _)  = self . targets [ new_local] 
405+                 && let  & [ PlaceElem :: Deref ]  = & target. projection [ ..] 
406+             { 
407+                 new_local = target. local ; 
408+             } 
409+             if  place. local  != new_local { 
410+                 self . remap_var_debug_infos [ place. local ]  = Some ( new_local) ; 
411+                 place. local  = new_local; 
412+ 
413+                 self . any_replacement  = true ; 
414+             } 
404415        } 
405416
406417        // Simplify eventual projections left inside `debuginfo`. 
407418        self . super_var_debug_info ( debuginfo) ; 
408419    } 
409420
421+     fn  visit_statement_debuginfo ( 
422+         & mut  self , 
423+         stmt_debuginfo :  & mut  StmtDebugInfo < ' tcx > , 
424+         location :  Location , 
425+     )  { 
426+         let  local = match  stmt_debuginfo { 
427+             StmtDebugInfo :: AssignRef ( local,  _)  | StmtDebugInfo :: InvalidAssign ( local)  => local, 
428+         } ; 
429+         if  let  Some ( target)  = self . remap_var_debug_infos [ * local]  { 
430+             * local = target; 
431+             self . any_replacement  = true ; 
432+         } 
433+         self . super_statement_debuginfo ( stmt_debuginfo,  location) ; 
434+     } 
435+ 
410436    fn  visit_place ( & mut  self ,  place :  & mut  Place < ' tcx > ,  ctxt :  PlaceContext ,  loc :  Location )  { 
411437        loop  { 
412438            let  Some ( ( & PlaceElem :: Deref ,  rest) )  = place. projection . split_first ( )  else  {  return  } ; 
@@ -437,8 +463,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
437463            { 
438464                stmt. make_nop ( true ) ; 
439465            } 
440-             // Do not remove assignments as they may still be useful for debuginfo. 
441-             _ => self . super_statement ( stmt,  loc) , 
466+             _ => { } 
442467        } 
468+         // Do not remove assignments as they may still be useful for debuginfo. 
469+         self . super_statement ( stmt,  loc) ; 
443470    } 
444471} 
0 commit comments