Skip to content

Commit 67a0d27

Browse files
committed
Ensure we walk the root module of the crate
1 parent bb8d51c commit 67a0d27

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

src/librustc_save_analysis/data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub struct ModData {
267267
pub items: Vec<NodeId>,
268268
pub visibility: Visibility,
269269
pub docs: String,
270-
pub sig: Signature,
270+
pub sig: Option<Signature>,
271271
pub attributes: Vec<Attribute>,
272272
}
273273

src/librustc_save_analysis/dump_visitor.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,33 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
12111211
}
12121212

12131213
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
1214+
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, id: NodeId) {
1215+
// Since we handle explicit modules ourselves in visit_item, this should
1216+
// only get called for the root module of a crate.
1217+
assert_eq!(id, ast::CRATE_NODE_ID);
1218+
1219+
let qualname = format!("::{}", self.tcx.node_path_str(id));
1220+
1221+
let cm = self.tcx.sess.codemap();
1222+
let filename = cm.span_to_filename(span);
1223+
self.dumper.mod_data(ModData {
1224+
id: id,
1225+
name: String::new(),
1226+
qualname: qualname,
1227+
span: span,
1228+
scope: id,
1229+
filename: filename,
1230+
items: m.items.iter().map(|i| i.id).collect(),
1231+
visibility: Visibility::Public,
1232+
// TODO Visitor doesn't pass us the attibutes.
1233+
docs: String::new(),
1234+
sig: None,
1235+
// TODO Visitor doesn't pass us the attibutes.
1236+
attributes: vec![],
1237+
}.lower(self.tcx));
1238+
self.nest_scope(id, |v| visit::walk_mod(v, m));
1239+
}
1240+
12141241
fn visit_item(&mut self, item: &'l ast::Item) {
12151242
use syntax::ast::ItemKind::*;
12161243
self.process_macro_use(item.span, item.id);

src/librustc_save_analysis/external_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub struct ModData {
392392
pub items: Vec<DefId>,
393393
pub visibility: Visibility,
394394
pub docs: String,
395-
pub sig: Signature,
395+
pub sig: Option<Signature>,
396396
pub attributes: Vec<Attribute>,
397397
}
398398

@@ -410,7 +410,7 @@ impl Lower for data::ModData {
410410
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
411411
visibility: self.visibility,
412412
docs: self.docs,
413-
sig: self.sig.lower(tcx),
413+
sig: self.sig.map(|s| s.lower(tcx)),
414414
attributes: self.attributes.lower(tcx),
415415
}
416416
}

src/librustc_save_analysis/json_api_dumper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Into<Option<Def>> for ModData {
293293
parent: None,
294294
decl_id: None,
295295
docs: self.docs,
296-
sig: Some(self.sig.into()),
296+
sig: self.sig.map(|s| s.into()),
297297
attributes: vec![],
298298
}),
299299
_ => None,

src/librustc_save_analysis/json_dumper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
121121
children: data.items.into_iter().map(|id| id_from_def_id(id)).collect(),
122122
decl_id: None,
123123
docs: data.docs,
124-
sig: Some(data.sig.into()),
124+
sig: data.sig.map(|s| s.into()),
125125
attributes: data.attributes.into_iter().map(|a| a.into()).collect(),
126126
};
127127
if def.span.file_name.to_str().unwrap() != def.value {

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
257257
items: m.items.iter().map(|i| i.id).collect(),
258258
visibility: From::from(&item.vis),
259259
docs: docs_for_attrs(&item.attrs),
260-
sig: self.sig_base(item),
260+
sig: Some(self.sig_base(item)),
261261
attributes: item.attrs.clone(),
262262
}))
263263
}

0 commit comments

Comments
 (0)