Ensure we walk the root module of the crate
This commit is contained in:
parent
bb8d51c2eb
commit
67a0d27c65
6 changed files with 33 additions and 6 deletions
|
@ -267,7 +267,7 @@ pub struct ModData {
|
||||||
pub items: Vec<NodeId>,
|
pub items: Vec<NodeId>,
|
||||||
pub visibility: Visibility,
|
pub visibility: Visibility,
|
||||||
pub docs: String,
|
pub docs: String,
|
||||||
pub sig: Signature,
|
pub sig: Option<Signature>,
|
||||||
pub attributes: Vec<Attribute>,
|
pub attributes: Vec<Attribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1211,6 +1211,33 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
|
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
|
||||||
|
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, id: NodeId) {
|
||||||
|
// Since we handle explicit modules ourselves in visit_item, this should
|
||||||
|
// only get called for the root module of a crate.
|
||||||
|
assert_eq!(id, ast::CRATE_NODE_ID);
|
||||||
|
|
||||||
|
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
||||||
|
|
||||||
|
let cm = self.tcx.sess.codemap();
|
||||||
|
let filename = cm.span_to_filename(span);
|
||||||
|
self.dumper.mod_data(ModData {
|
||||||
|
id: id,
|
||||||
|
name: String::new(),
|
||||||
|
qualname: qualname,
|
||||||
|
span: span,
|
||||||
|
scope: id,
|
||||||
|
filename: filename,
|
||||||
|
items: m.items.iter().map(|i| i.id).collect(),
|
||||||
|
visibility: Visibility::Public,
|
||||||
|
// TODO Visitor doesn't pass us the attibutes.
|
||||||
|
docs: String::new(),
|
||||||
|
sig: None,
|
||||||
|
// TODO Visitor doesn't pass us the attibutes.
|
||||||
|
attributes: vec![],
|
||||||
|
}.lower(self.tcx));
|
||||||
|
self.nest_scope(id, |v| visit::walk_mod(v, m));
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &'l ast::Item) {
|
fn visit_item(&mut self, item: &'l ast::Item) {
|
||||||
use syntax::ast::ItemKind::*;
|
use syntax::ast::ItemKind::*;
|
||||||
self.process_macro_use(item.span, item.id);
|
self.process_macro_use(item.span, item.id);
|
||||||
|
|
|
@ -392,7 +392,7 @@ pub struct ModData {
|
||||||
pub items: Vec<DefId>,
|
pub items: Vec<DefId>,
|
||||||
pub visibility: Visibility,
|
pub visibility: Visibility,
|
||||||
pub docs: String,
|
pub docs: String,
|
||||||
pub sig: Signature,
|
pub sig: Option<Signature>,
|
||||||
pub attributes: Vec<Attribute>,
|
pub attributes: Vec<Attribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ impl Lower for data::ModData {
|
||||||
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
|
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
|
||||||
visibility: self.visibility,
|
visibility: self.visibility,
|
||||||
docs: self.docs,
|
docs: self.docs,
|
||||||
sig: self.sig.lower(tcx),
|
sig: self.sig.map(|s| s.lower(tcx)),
|
||||||
attributes: self.attributes.lower(tcx),
|
attributes: self.attributes.lower(tcx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ impl Into<Option<Def>> for ModData {
|
||||||
parent: None,
|
parent: None,
|
||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: self.docs,
|
docs: self.docs,
|
||||||
sig: Some(self.sig.into()),
|
sig: self.sig.map(|s| s.into()),
|
||||||
attributes: vec![],
|
attributes: vec![],
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
|
||||||
children: data.items.into_iter().map(|id| id_from_def_id(id)).collect(),
|
children: data.items.into_iter().map(|id| id_from_def_id(id)).collect(),
|
||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: data.docs,
|
docs: data.docs,
|
||||||
sig: Some(data.sig.into()),
|
sig: data.sig.map(|s| s.into()),
|
||||||
attributes: data.attributes.into_iter().map(|a| a.into()).collect(),
|
attributes: data.attributes.into_iter().map(|a| a.into()).collect(),
|
||||||
};
|
};
|
||||||
if def.span.file_name.to_str().unwrap() != def.value {
|
if def.span.file_name.to_str().unwrap() != def.value {
|
||||||
|
|
|
@ -257,7 +257,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||||
items: m.items.iter().map(|i| i.id).collect(),
|
items: m.items.iter().map(|i| i.id).collect(),
|
||||||
visibility: From::from(&item.vis),
|
visibility: From::from(&item.vis),
|
||||||
docs: docs_for_attrs(&item.attrs),
|
docs: docs_for_attrs(&item.attrs),
|
||||||
sig: self.sig_base(item),
|
sig: Some(self.sig_base(item)),
|
||||||
attributes: item.attrs.clone(),
|
attributes: item.attrs.clone(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue