Skip to content

Commit b629ffd

Browse files
committed
liveness: Use visit_param to add variables corresponding to params
1 parent e0db21d commit b629ffd

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

compiler/rustc_passes/src/liveness.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
165165
fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
166166
visit_arm(self, a);
167167
}
168+
fn visit_param(&mut self, p: &'tcx hir::Param<'tcx>) {
169+
visit_param(self, p);
170+
}
168171
}
169172

170173
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
@@ -334,21 +337,6 @@ fn visit_fn<'tcx>(
334337
}
335338
}
336339

337-
for param in body.params {
338-
let is_shorthand = match param.pat.kind {
339-
rustc_hir::PatKind::Struct(..) => true,
340-
_ => false,
341-
};
342-
param.pat.each_binding(|_bm, hir_id, _x, ident| {
343-
let var = if is_shorthand {
344-
Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })
345-
} else {
346-
Param(hir_id, ident.name)
347-
};
348-
fn_maps.add_variable(var);
349-
})
350-
}
351-
352340
// gather up the various local variables, significant expressions,
353341
// and so forth:
354342
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>) {
415403
intravisit::walk_arm(ir, arm);
416404
}
417405

406+
fn visit_param<'tcx>(ir: &mut IrMaps<'tcx>, param: &'tcx hir::Param<'tcx>) {
407+
let is_shorthand = match param.pat.kind {
408+
rustc_hir::PatKind::Struct(..) => true,
409+
_ => false,
410+
};
411+
param.pat.each_binding(|_bm, hir_id, _x, ident| {
412+
let var = if is_shorthand {
413+
Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })
414+
} else {
415+
Param(hir_id, ident.name)
416+
};
417+
ir.add_variable(var);
418+
});
419+
intravisit::walk_param(ir, param);
420+
}
421+
418422
fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
419423
match expr.kind {
420424
// live nodes required for uses or definitions of variables:

0 commit comments

Comments
 (0)