diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-11-09 20:57:48 +0200 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-11-28 05:12:41 +0200 |
| commit | fcdb4def834b581739df7f2d044d015c557d3f32 (patch) | |
| tree | 71cb7f328f4c047649c35dbf8659679cf7cc94a9 /src | |
| parent | 36d33d6b71cb99ad9d9403295daec8d8a8f5c976 (diff) | |
| download | rust-fcdb4def834b581739df7f2d044d015c557d3f32.tar.gz rust-fcdb4def834b581739df7f2d044d015c557d3f32.zip | |
rustc: track fields in the HIR map.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/hir/map/collector.rs | 7 | ||||
| -rw-r--r-- | src/librustc/hir/map/mod.rs | 18 | ||||
| -rw-r--r-- | src/librustc/middle/reachable.rs | 1 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 67e9b24f42d..26fd2b736a4 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -242,4 +242,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) { self.insert_entry(macro_def.id, NotPresent); } + + fn visit_struct_field(&mut self, field: &'ast StructField) { + self.insert(field.id, NodeField(field)); + self.with_parent(field.id, |this| { + intravisit::walk_struct_field(this, field); + }); + } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index c4ed98ce6e0..b9763e6ea0d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -46,6 +46,7 @@ pub enum Node<'ast> { NodeTraitItem(&'ast TraitItem), NodeImplItem(&'ast ImplItem), NodeVariant(&'ast Variant), + NodeField(&'ast StructField), NodeExpr(&'ast Expr), NodeStmt(&'ast Stmt), NodeTy(&'ast Ty), @@ -75,6 +76,7 @@ pub enum MapEntry<'ast> { EntryTraitItem(NodeId, &'ast TraitItem), EntryImplItem(NodeId, &'ast ImplItem), EntryVariant(NodeId, &'ast Variant), + EntryField(NodeId, &'ast StructField), EntryExpr(NodeId, &'ast Expr), EntryStmt(NodeId, &'ast Stmt), EntryTy(NodeId, &'ast Ty), @@ -106,6 +108,7 @@ impl<'ast> MapEntry<'ast> { NodeTraitItem(n) => EntryTraitItem(p, n), NodeImplItem(n) => EntryImplItem(p, n), NodeVariant(n) => EntryVariant(p, n), + NodeField(n) => EntryField(p, n), NodeExpr(n) => EntryExpr(p, n), NodeStmt(n) => EntryStmt(p, n), NodeTy(n) => EntryTy(p, n), @@ -127,6 +130,7 @@ impl<'ast> MapEntry<'ast> { EntryTraitItem(id, _) => id, EntryImplItem(id, _) => id, EntryVariant(id, _) => id, + EntryField(id, _) => id, EntryExpr(id, _) => id, EntryStmt(id, _) => id, EntryTy(id, _) => id, @@ -152,6 +156,7 @@ impl<'ast> MapEntry<'ast> { EntryTraitItem(_, n) => NodeTraitItem(n), EntryImplItem(_, n) => NodeImplItem(n), EntryVariant(_, n) => NodeVariant(n), + EntryField(_, n) => NodeField(n), EntryExpr(_, n) => NodeExpr(n), EntryStmt(_, n) => NodeStmt(n), EntryTy(_, n) => NodeTy(n), @@ -265,6 +270,7 @@ impl<'ast> Map<'ast> { EntryForeignItem(p, _) | EntryTraitItem(p, _) | EntryVariant(p, _) | + EntryField(p, _) | EntryExpr(p, _) | EntryStmt(p, _) | EntryTy(p, _) | @@ -308,6 +314,7 @@ impl<'ast> Map<'ast> { EntryTraitItem(p, _) | EntryImplItem(p, _) | EntryVariant(p, _) | + EntryField(p, _) | EntryExpr(p, _) | EntryStmt(p, _) | EntryTy(p, _) | @@ -656,6 +663,7 @@ impl<'ast> Map<'ast> { NodeImplItem(ii) => ii.name, NodeTraitItem(ti) => ti.name, NodeVariant(v) => v.node.name, + NodeField(f) => f.name, NodeLifetime(lt) => lt.name, NodeTyParam(tp) => tp.name, NodeLocal(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node, @@ -674,6 +682,7 @@ impl<'ast> Map<'ast> { Some(NodeTraitItem(ref ti)) => Some(&ti.attrs[..]), Some(NodeImplItem(ref ii)) => Some(&ii.attrs[..]), Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]), + Some(NodeField(ref f)) => Some(&f.attrs[..]), Some(NodeExpr(ref e)) => Some(&*e.attrs), Some(NodeStmt(ref s)) => Some(s.node.attrs()), // unit/tuple structs take the attributes straight from @@ -710,6 +719,7 @@ impl<'ast> Map<'ast> { Some(NodeTraitItem(trait_method)) => trait_method.span, Some(NodeImplItem(ref impl_item)) => impl_item.span, Some(NodeVariant(variant)) => variant.span, + Some(NodeField(field)) => field.span, Some(NodeExpr(expr)) => expr.span, Some(NodeStmt(stmt)) => stmt.span, Some(NodeTy(ty)) => ty.span, @@ -831,6 +841,7 @@ impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> { Some(EntryTraitItem(_, n)) => n.name(), Some(EntryImplItem(_, n)) => n.name(), Some(EntryVariant(_, n)) => n.name(), + Some(EntryField(_, n)) => n.name(), _ => continue, }; if self.matches_names(self.map.get_parent(idx), name) { @@ -849,6 +860,7 @@ impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } impl Named for Item { fn name(&self) -> Name { self.name } } impl Named for ForeignItem { fn name(&self) -> Name { self.name } } impl Named for Variant_ { fn name(&self) -> Name { self.name } } +impl Named for StructField { fn name(&self) -> Name { self.name } } impl Named for TraitItem { fn name(&self) -> Name { self.name } } impl Named for ImplItem { fn name(&self) -> Name { self.name } } @@ -940,6 +952,7 @@ impl<'a> NodePrinter for pprust::State<'a> { NodeLifetime(a) => self.print_lifetime(&a), NodeVisibility(a) => self.print_visibility(&a), NodeTyParam(_) => bug!("cannot print TyParam"), + NodeField(_) => bug!("cannot print StructField"), // these cases do not carry enough information in the // ast_map to reconstruct their full structure for pretty // printing. @@ -1019,6 +1032,11 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { variant.node.name, path_str(), id_str) } + Some(NodeField(ref field)) => { + format!("field {} in {}{}", + field.name, + path_str(), id_str) + } Some(NodeExpr(ref expr)) => { format!("expr {}{}", pprust::expr_to_string(&expr), id_str) } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 767886a2315..b17d41e0fa5 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -299,6 +299,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { ast_map::NodeForeignItem(_) | ast_map::NodeVariant(_) | ast_map::NodeStructCtor(_) | + ast_map::NodeField(_) | ast_map::NodeTy(_) => {} _ => { bug!("found unexpected thingy in worklist: {}", |
