Skip to content

Commit 04a7675

Browse files
committed
For loops in save-analysis
1 parent 20083c1 commit 04a7675

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

src/librustc_trans/save/dump_csv.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,35 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
796796
_ => visit::walk_pat(self, p),
797797
}
798798
}
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+
}
799828
}
800829

801830
impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
@@ -1103,6 +1132,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11031132
// walk the body
11041133
self.nest(ex.id, |v| v.visit_block(&**body));
11051134
}
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+
}
11061141
_ => {
11071142
visit::walk_expr(self, ex)
11081143
}
@@ -1180,31 +1215,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11801215
return
11811216
}
11821217

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-
11891218
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);
12051220

12061221
// Just walk the initialiser and type (don't want to walk the pattern again).
12071222
walk_list!(self, visit_ty, &l.ty);
12081223
walk_list!(self, visit_expr, &l.init);
12091224
}
12101225
}
1226+

0 commit comments

Comments
 (0)