about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-07-01 09:01:33 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-07-10 16:01:19 +0000
commita5031d569e69bc8e6ff7d10b22bbab1e946b62b0 (patch)
treef4c39b4209068441f343c0ee37cf7f6052d7cc61 /compiler/rustc_mir_transform/src
parentb4c342edea675e5dce844e90af276a4e79834e3b (diff)
downloadrust-a5031d569e69bc8e6ff7d10b22bbab1e946b62b0.tar.gz
rust-a5031d569e69bc8e6ff7d10b22bbab1e946b62b0.zip
Call super for debuginfo.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/ref_prop.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs
index d296788d268..c17c791f9c3 100644
--- a/compiler/rustc_mir_transform/src/ref_prop.rs
+++ b/compiler/rustc_mir_transform/src/ref_prop.rs
@@ -355,7 +355,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
     }
 
     fn visit_var_debug_info(&mut self, debuginfo: &mut VarDebugInfo<'tcx>) {
-        if let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
+        // If the debuginfo is a pointer to another place:
+        // - if it's a reborrow, see through it;
+        // - if it's a direct borrow, increase `debuginfo.references`.
+        while let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
             && place.projection.is_empty()
             && let Value::Pointer(target, _) = self.targets[place.local]
             && target.projection.iter().all(|p| p.can_use_in_debuginfo())
@@ -369,8 +372,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
                 debuginfo.references = references;
                 *place = target;
                 self.any_replacement = true;
+            } else {
+                break
             }
         }
+
+        // Simplify eventual projections left inside `debuginfo`.
+        self.super_var_debug_info(debuginfo);
     }
 
     fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
@@ -381,8 +389,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
 
             let Value::Pointer(target, _) = self.targets[place.local] else { return };
 
-            let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
-                || self.allowed_replacements.contains(&(target.local, loc));
+            let perform_opt = match ctxt {
+                PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {
+                    target.projection.iter().all(|p| p.can_use_in_debuginfo())
+                }
+                PlaceContext::NonUse(_) => true,
+                _ => self.allowed_replacements.contains(&(target.local, loc)),
+            };
 
             if !perform_opt {
                 return;