Skip to content

Commit be95dee

Browse files
committed
or-patterns: adjust save_analysis wrt. process_var_decl{_multi}.
1 parent a867c5f commit be95dee

File tree

2 files changed

+15
-83
lines changed

2 files changed

+15
-83
lines changed

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -897,32 +897,23 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
897897
}
898898
}
899899

900-
fn process_var_decl_multi(&mut self, pats: &'l [P<ast::Pat>]) {
900+
fn process_var_decl(&mut self, pat: &'l ast::Pat) {
901+
// The pattern could declare multiple new vars,
902+
// we must walk the pattern and collect them all.
901903
let mut collector = PathCollector::new();
902-
for pattern in pats {
903-
// collect paths from the arm's patterns
904-
collector.visit_pat(&pattern);
905-
self.visit_pat(&pattern);
906-
}
904+
collector.visit_pat(&pat);
905+
self.visit_pat(&pat);
907906

908-
// process collected paths
909-
for (id, ident, immut) in collector.collected_idents {
907+
// Process collected paths.
908+
for (id, ident, _) in collector.collected_idents {
910909
match self.save_ctxt.get_path_res(id) {
911910
Res::Local(hir_id) => {
912-
let mut value = if immut == ast::Mutability::Immutable {
913-
self.span.snippet(ident.span)
914-
} else {
915-
"<mutable>".to_owned()
916-
};
917911
let id = self.tcx.hir().hir_to_node_id(hir_id);
918-
let typ = self.save_ctxt
919-
.tables
920-
.node_type_opt(hir_id)
912+
let typ = self.save_ctxt.tables.node_type_opt(hir_id)
921913
.map(|t| t.to_string())
922914
.unwrap_or_default();
923-
value.push_str(": ");
924-
value.push_str(&typ);
925915

916+
// Rust uses the id of the pattern for var lookups, so we'll use it too.
926917
if !self.span.filter_generated(ident.span) {
927918
let qualname = format!("{}${}", ident.to_string(), id);
928919
let id = id_from_node_id(id, &self.save_ctxt);
@@ -972,61 +963,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
972963
}
973964
}
974965

975-
fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
976-
// The local could declare multiple new vars, we must walk the
977-
// pattern and collect them all.
978-
let mut collector = PathCollector::new();
979-
collector.visit_pat(&p);
980-
self.visit_pat(&p);
981-
982-
for (id, ident, immut) in collector.collected_idents {
983-
let mut value = match immut {
984-
ast::Mutability::Immutable => value.to_string(),
985-
_ => String::new(),
986-
};
987-
let hir_id = self.tcx.hir().node_to_hir_id(id);
988-
let typ = match self.save_ctxt.tables.node_type_opt(hir_id) {
989-
Some(typ) => {
990-
let typ = typ.to_string();
991-
if !value.is_empty() {
992-
value.push_str(": ");
993-
}
994-
value.push_str(&typ);
995-
typ
996-
}
997-
None => String::new(),
998-
};
999-
1000-
// Rust uses the id of the pattern for var lookups, so we'll use it too.
1001-
if !self.span.filter_generated(ident.span) {
1002-
let qualname = format!("{}${}", ident.to_string(), id);
1003-
let id = id_from_node_id(id, &self.save_ctxt);
1004-
let span = self.span_from_span(ident.span);
1005-
1006-
self.dumper.dump_def(
1007-
&Access {
1008-
public: false,
1009-
reachable: false,
1010-
},
1011-
Def {
1012-
kind: DefKind::Local,
1013-
id,
1014-
span,
1015-
name: ident.to_string(),
1016-
qualname,
1017-
value: typ,
1018-
parent: None,
1019-
children: vec![],
1020-
decl_id: None,
1021-
docs: String::new(),
1022-
sig: None,
1023-
attributes: vec![],
1024-
},
1025-
);
1026-
}
1027-
}
1028-
}
1029-
1030966
/// Extracts macro use and definition information from the AST node defined
1031967
/// by the given NodeId, using the expansion information from the node's
1032968
/// span.
@@ -1565,14 +1501,13 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
15651501
});
15661502
}
15671503
ast::ExprKind::ForLoop(ref pattern, ref subexpression, ref block, _) => {
1568-
let value = self.span.snippet(subexpression.span);
1569-
self.process_var_decl(pattern, value);
1504+
self.process_var_decl(pattern);
15701505
debug!("for loop, walk sub-expr: {:?}", subexpression.node);
15711506
self.visit_expr(subexpression);
15721507
visit::walk_block(self, block);
15731508
}
1574-
ast::ExprKind::Let(ref pats, ref scrutinee) => {
1575-
self.process_var_decl_multi(pats);
1509+
ast::ExprKind::Let(ref pat, ref scrutinee) => {
1510+
self.process_var_decl(pat);
15761511
self.visit_expr(scrutinee);
15771512
}
15781513
ast::ExprKind::Repeat(ref element, ref count) => {
@@ -1599,7 +1534,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
15991534
}
16001535

16011536
fn visit_arm(&mut self, arm: &'l ast::Arm) {
1602-
self.process_var_decl_multi(&arm.pats);
1537+
self.process_var_decl(&arm.pat);
16031538
if let Some(expr) = &arm.guard {
16041539
self.visit_expr(expr);
16051540
}
@@ -1617,11 +1552,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
16171552

16181553
fn visit_local(&mut self, l: &'l ast::Local) {
16191554
self.process_macro_use(l.span);
1620-
let value = l.init
1621-
.as_ref()
1622-
.map(|i| self.span.snippet(i.span))
1623-
.unwrap_or_default();
1624-
self.process_var_decl(&l.pat, value);
1555+
self.process_var_decl(&l.pat);
16251556

16261557
// Just walk the initialiser and type (don't want to walk the pattern again).
16271558
walk_list!(self, visit_ty, &l.ty);

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
22
#![feature(nll)]
3+
#![feature(inner_deref)]
34

45
#![recursion_limit="256"]
56

0 commit comments

Comments
 (0)