Skip to content

Commit

Permalink
Ensure we walk the root module of the crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 11, 2017
1 parent bb8d51c commit 67a0d27
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/data.rs
Expand Up @@ -267,7 +267,7 @@ pub struct ModData {
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}

Expand Down
27 changes: 27 additions & 0 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -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> {
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) {
use syntax::ast::ItemKind::*;
self.process_macro_use(item.span, item.id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/external_data.rs
Expand Up @@ -392,7 +392,7 @@ pub struct ModData {
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}

Expand All @@ -410,7 +410,7 @@ impl Lower for data::ModData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig.map(|s| s.lower(tcx)),
attributes: self.attributes.lower(tcx),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/json_api_dumper.rs
Expand Up @@ -293,7 +293,7 @@ impl Into<Option<Def>> for ModData {
parent: None,
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig.map(|s| s.into()),
attributes: vec![],
}),
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/json_dumper.rs
Expand Up @@ -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(),
decl_id: None,
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(),
};
if def.span.file_name.to_str().unwrap() != def.value {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -257,7 +257,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
items: m.items.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: self.sig_base(item),
sig: Some(self.sig_base(item)),
attributes: item.attrs.clone(),
}))
}
Expand Down

0 comments on commit 67a0d27

Please sign in to comment.