@@ -1031,6 +1031,81 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10311031 }
10321032 }
10331033
1034+ fn process_var_decl_multi ( & mut self , pats : & ' l [ P < ast:: Pat > ] ) {
1035+ let mut collector = PathCollector :: new ( ) ;
1036+ for pattern in pats {
1037+ // collect paths from the arm's patterns
1038+ collector. visit_pat ( & pattern) ;
1039+ self . visit_pat ( & pattern) ;
1040+ }
1041+
1042+ // process collected paths
1043+ for ( id, i, sp, immut) in collector. collected_idents {
1044+ match self . save_ctxt . get_path_def ( id) {
1045+ HirDef :: Local ( id) => {
1046+ let mut value = if immut == ast:: Mutability :: Immutable {
1047+ self . span . snippet ( sp) . to_string ( )
1048+ } else {
1049+ "<mutable>" . to_string ( )
1050+ } ;
1051+ let hir_id = self . tcx . hir . node_to_hir_id ( id) ;
1052+ let typ = self . save_ctxt
1053+ . tables
1054+ . node_id_to_type_opt ( hir_id)
1055+ . map ( |t| t. to_string ( ) )
1056+ . unwrap_or ( String :: new ( ) ) ;
1057+ value. push_str ( ": " ) ;
1058+ value. push_str ( & typ) ;
1059+
1060+ if !self . span . filter_generated ( Some ( sp) , sp) {
1061+ let qualname = format ! ( "{}${}" , i. to_string( ) , id) ;
1062+ let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
1063+ let span = self . span_from_span ( sp) ;
1064+
1065+ self . dumper . dump_def (
1066+ & Access {
1067+ public : false ,
1068+ reachable : false ,
1069+ } ,
1070+ Def {
1071+ kind : DefKind :: Local ,
1072+ id,
1073+ span,
1074+ name : i. to_string ( ) ,
1075+ qualname,
1076+ value : typ,
1077+ parent : None ,
1078+ children : vec ! [ ] ,
1079+ decl_id : None ,
1080+ docs : String :: new ( ) ,
1081+ sig : None ,
1082+ attributes : vec ! [ ] ,
1083+ } ,
1084+ ) ;
1085+ }
1086+ }
1087+ HirDef :: StructCtor ( ..) |
1088+ HirDef :: VariantCtor ( ..) |
1089+ HirDef :: Const ( ..) |
1090+ HirDef :: AssociatedConst ( ..) |
1091+ HirDef :: Struct ( ..) |
1092+ HirDef :: Variant ( ..) |
1093+ HirDef :: TyAlias ( ..) |
1094+ HirDef :: AssociatedTy ( ..) |
1095+ HirDef :: SelfTy ( ..) => {
1096+ self . dump_path_ref ( id, & ast:: Path :: from_ident ( sp, i) ) ;
1097+ }
1098+ def => error ! (
1099+ "unexpected definition kind when processing collected idents: {:?}" ,
1100+ def
1101+ ) ,
1102+ }
1103+ }
1104+
1105+ for ( id, ref path) in collector. collected_paths {
1106+ self . process_path ( id, path) ;
1107+ }
1108+ }
10341109
10351110 fn process_var_decl ( & mut self , p : & ' l ast:: Pat , value : String ) {
10361111 // The local could declare multiple new vars, we must walk the
@@ -1622,17 +1697,21 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
16221697 v. nest_scope ( ex. id , |v| v. visit_expr ( body) )
16231698 } ) ;
16241699 }
1625- ast:: ExprKind :: ForLoop ( ref pattern, ref subexpression, ref block, _) |
1626- ast:: ExprKind :: WhileLet ( ref pattern, ref subexpression, ref block, _) => {
1700+ ast:: ExprKind :: ForLoop ( ref pattern, ref subexpression, ref block, _) => {
16271701 let value = self . span . snippet ( subexpression. span ) ;
16281702 self . process_var_decl ( pattern, value) ;
16291703 debug ! ( "for loop, walk sub-expr: {:?}" , subexpression. node) ;
16301704 self . visit_expr ( subexpression) ;
16311705 visit:: walk_block ( self , block) ;
16321706 }
1633- ast:: ExprKind :: IfLet ( ref pattern, ref subexpression, ref block, ref opt_else) => {
1634- let value = self . span . snippet ( subexpression. span ) ;
1635- self . process_var_decl ( pattern, value) ;
1707+ ast:: ExprKind :: WhileLet ( ref pats, ref subexpression, ref block, _) => {
1708+ self . process_var_decl_multi ( pats) ;
1709+ debug ! ( "for loop, walk sub-expr: {:?}" , subexpression. node) ;
1710+ self . visit_expr ( subexpression) ;
1711+ visit:: walk_block ( self , block) ;
1712+ }
1713+ ast:: ExprKind :: IfLet ( ref pats, ref subexpression, ref block, ref opt_else) => {
1714+ self . process_var_decl_multi ( pats) ;
16361715 self . visit_expr ( subexpression) ;
16371716 visit:: walk_block ( self , block) ;
16381717 opt_else. as_ref ( ) . map ( |el| self . visit_expr ( el) ) ;
@@ -1661,79 +1740,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
16611740 }
16621741
16631742 fn visit_arm ( & mut self , arm : & ' l ast:: Arm ) {
1664- let mut collector = PathCollector :: new ( ) ;
1665- for pattern in & arm. pats {
1666- // collect paths from the arm's patterns
1667- collector. visit_pat ( & pattern) ;
1668- self . visit_pat ( & pattern) ;
1669- }
1670-
1671- // process collected paths
1672- for ( id, i, sp, immut) in collector. collected_idents {
1673- match self . save_ctxt . get_path_def ( id) {
1674- HirDef :: Local ( id) => {
1675- let mut value = if immut == ast:: Mutability :: Immutable {
1676- self . span . snippet ( sp) . to_string ( )
1677- } else {
1678- "<mutable>" . to_string ( )
1679- } ;
1680- let hir_id = self . tcx . hir . node_to_hir_id ( id) ;
1681- let typ = self . save_ctxt
1682- . tables
1683- . node_id_to_type_opt ( hir_id)
1684- . map ( |t| t. to_string ( ) )
1685- . unwrap_or ( String :: new ( ) ) ;
1686- value. push_str ( ": " ) ;
1687- value. push_str ( & typ) ;
1688-
1689- if !self . span . filter_generated ( Some ( sp) , sp) {
1690- let qualname = format ! ( "{}${}" , i. to_string( ) , id) ;
1691- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
1692- let span = self . span_from_span ( sp) ;
1693-
1694- self . dumper . dump_def (
1695- & Access {
1696- public : false ,
1697- reachable : false ,
1698- } ,
1699- Def {
1700- kind : DefKind :: Local ,
1701- id,
1702- span,
1703- name : i. to_string ( ) ,
1704- qualname,
1705- value : typ,
1706- parent : None ,
1707- children : vec ! [ ] ,
1708- decl_id : None ,
1709- docs : String :: new ( ) ,
1710- sig : None ,
1711- attributes : vec ! [ ] ,
1712- } ,
1713- ) ;
1714- }
1715- }
1716- HirDef :: StructCtor ( ..) |
1717- HirDef :: VariantCtor ( ..) |
1718- HirDef :: Const ( ..) |
1719- HirDef :: AssociatedConst ( ..) |
1720- HirDef :: Struct ( ..) |
1721- HirDef :: Variant ( ..) |
1722- HirDef :: TyAlias ( ..) |
1723- HirDef :: AssociatedTy ( ..) |
1724- HirDef :: SelfTy ( ..) => {
1725- self . dump_path_ref ( id, & ast:: Path :: from_ident ( sp, i) ) ;
1726- }
1727- def => error ! (
1728- "unexpected definition kind when processing collected idents: {:?}" ,
1729- def
1730- ) ,
1731- }
1732- }
1733-
1734- for ( id, ref path) in collector. collected_paths {
1735- self . process_path ( id, path) ;
1736- }
1743+ self . process_var_decl_multi ( & arm. pats ) ;
17371744 walk_list ! ( self , visit_expr, & arm. guard) ;
17381745 self . visit_expr ( & arm. body ) ;
17391746 }
0 commit comments