@@ -796,6 +796,35 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
796
796
_ => visit:: walk_pat ( self , p) ,
797
797
}
798
798
}
799
+
800
+
801
+ fn process_var_decl ( & mut self , p : & ast:: Pat , value : String ) {
802
+ // The local could declare multiple new vars, we must walk the
803
+ // pattern and collect them all.
804
+ let mut collector = PathCollector :: new ( ) ;
805
+ collector. visit_pat ( & p) ;
806
+ self . visit_pat ( & p) ;
807
+
808
+ for & ( id, ref p, immut, _) in & collector. collected_paths {
809
+ let value = if immut == ast:: MutImmutable {
810
+ value. to_string ( )
811
+ } else {
812
+ "<mutable>" . to_string ( )
813
+ } ;
814
+ let types = self . tcx . node_types ( ) ;
815
+ let typ = types. get ( & id) . unwrap ( ) . to_string ( ) ;
816
+ // Get the span only for the name of the variable (I hope the path
817
+ // is only ever a variable name, but who knows?).
818
+ let sub_span = self . span . span_for_last_ident ( p. span ) ;
819
+ // Rust uses the id of the pattern for var lookups, so we'll use it too.
820
+ self . fmt . variable_str ( p. span ,
821
+ sub_span,
822
+ id,
823
+ & path_to_string ( p) ,
824
+ & value,
825
+ & typ) ;
826
+ }
827
+ }
799
828
}
800
829
801
830
impl < ' l , ' tcx , ' v > Visitor < ' v > for DumpCsvVisitor < ' l , ' tcx > {
@@ -1103,6 +1132,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1103
1132
// walk the body
1104
1133
self . nest ( ex. id , |v| v. visit_block ( & * * body) ) ;
1105
1134
}
1135
+ ast:: ExprForLoop ( ref pattern, ref subexpression, ref block, _) => {
1136
+ let value = self . span . snippet ( mk_sp ( ex. span . lo , subexpression. span . hi ) ) ;
1137
+ self . process_var_decl ( pattern, value) ;
1138
+ visit:: walk_expr ( self , subexpression) ;
1139
+ visit:: walk_block ( self , block) ;
1140
+ }
1106
1141
_ => {
1107
1142
visit:: walk_expr ( self , ex)
1108
1143
}
@@ -1180,31 +1215,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1180
1215
return
1181
1216
}
1182
1217
1183
- // The local could declare multiple new vars, we must walk the
1184
- // pattern and collect them all.
1185
- let mut collector = PathCollector :: new ( ) ;
1186
- collector. visit_pat ( & l. pat ) ;
1187
- self . visit_pat ( & l. pat ) ;
1188
-
1189
1218
let value = self . span . snippet ( l. span ) ;
1190
-
1191
- for & ( id, ref p, immut, _) in & collector. collected_paths {
1192
- let value = if immut == ast:: MutImmutable {
1193
- value. to_string ( )
1194
- } else {
1195
- "<mutable>" . to_string ( )
1196
- } ;
1197
- let types = self . tcx . node_types ( ) ;
1198
- let typ = types. get ( & id) . unwrap ( ) . to_string ( ) ;
1199
- // Get the span only for the name of the variable (I hope the path
1200
- // is only ever a variable name, but who knows?).
1201
- let sub_span = self . span . span_for_last_ident ( p. span ) ;
1202
- // Rust uses the id of the pattern for var lookups, so we'll use it too.
1203
- self . fmt . variable_str ( p. span , sub_span, id, & path_to_string ( p) , & value, & typ) ;
1204
- }
1219
+ self . process_var_decl ( & l. pat , value) ;
1205
1220
1206
1221
// Just walk the initialiser and type (don't want to walk the pattern again).
1207
1222
walk_list ! ( self , visit_ty, & l. ty) ;
1208
1223
walk_list ! ( self , visit_expr, & l. init) ;
1209
1224
}
1210
1225
}
1226
+
0 commit comments