about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-27 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-27 23:55:53 +0200
commitb629ffd96bd4c882322833f6cde8c41b115894f9 (patch)
tree96f6b2c8ddbc845e0ce954c696b0616e2c2b13e4
parente0db21dc7e4c8ab897ff07dcf0cce293db6ff4da (diff)
downloadrust-b629ffd96bd4c882322833f6cde8c41b115894f9.tar.gz
rust-b629ffd96bd4c882322833f6cde8c41b115894f9.zip
liveness: Use visit_param to add variables corresponding to params
-rw-r--r--compiler/rustc_passes/src/liveness.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs
index 2cc9075196b..f399463e5ad 100644
--- a/compiler/rustc_passes/src/liveness.rs
+++ b/compiler/rustc_passes/src/liveness.rs
@@ -165,6 +165,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
     fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
         visit_arm(self, a);
     }
+    fn visit_param(&mut self, p: &'tcx hir::Param<'tcx>) {
+        visit_param(self, p);
+    }
 }
 
 fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
@@ -334,21 +337,6 @@ fn visit_fn<'tcx>(
         }
     }
 
-    for param in body.params {
-        let is_shorthand = match param.pat.kind {
-            rustc_hir::PatKind::Struct(..) => true,
-            _ => false,
-        };
-        param.pat.each_binding(|_bm, hir_id, _x, ident| {
-            let var = if is_shorthand {
-                Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })
-            } else {
-                Param(hir_id, ident.name)
-            };
-            fn_maps.add_variable(var);
-        })
-    }
-
     // gather up the various local variables, significant expressions,
     // and so forth:
     intravisit::walk_fn(&mut fn_maps, fk, decl, body_id, sp, id);
@@ -415,6 +403,22 @@ fn visit_arm<'tcx>(ir: &mut IrMaps<'tcx>, arm: &'tcx hir::Arm<'tcx>) {
     intravisit::walk_arm(ir, arm);
 }
 
+fn visit_param<'tcx>(ir: &mut IrMaps<'tcx>, param: &'tcx hir::Param<'tcx>) {
+    let is_shorthand = match param.pat.kind {
+        rustc_hir::PatKind::Struct(..) => true,
+        _ => false,
+    };
+    param.pat.each_binding(|_bm, hir_id, _x, ident| {
+        let var = if is_shorthand {
+            Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })
+        } else {
+            Param(hir_id, ident.name)
+        };
+        ir.add_variable(var);
+    });
+    intravisit::walk_param(ir, param);
+}
+
 fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
     match expr.kind {
         // live nodes required for uses or definitions of variables: