Skip to content

Commit a0a9f8c

Browse files
committedNov 10, 2016
Fix fallout in librustdoc.
1 parent 872943c commit a0a9f8c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed
 

‎src/librustdoc/core.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_driver::{driver, target_features, abort_on_err};
1414
use rustc::dep_graph::DepGraph;
1515
use rustc::session::{self, config};
1616
use rustc::hir::def_id::DefId;
17-
use rustc::hir::def::Def;
17+
use rustc::hir::def::{Def, ExportMap};
1818
use rustc::middle::privacy::AccessLevels;
1919
use rustc::ty::{self, TyCtxt};
2020
use rustc::hir::map as hir_map;
@@ -74,6 +74,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
7474
pub ty_substs: RefCell<FxHashMap<Def, clean::Type>>,
7575
/// Table node id of lifetime parameter definition -> substituted lifetime
7676
pub lt_substs: RefCell<FxHashMap<ast::NodeId, clean::Lifetime>>,
77+
pub export_map: ExportMap,
7778
}
7879

7980
impl<'b, 'tcx> DocContext<'b, 'tcx> {
@@ -196,7 +197,7 @@ pub fn run_core(search_paths: SearchPaths,
196197
sess.fatal("Compilation failed, aborting rustdoc");
197198
}
198199

199-
let ty::CrateAnalysis { access_levels, .. } = analysis;
200+
let ty::CrateAnalysis { access_levels, export_map, .. } = analysis;
200201

201202
// Convert from a NodeId set to a DefId set since we don't always have easy access
202203
// to the map from defid -> nodeid
@@ -218,6 +219,7 @@ pub fn run_core(search_paths: SearchPaths,
218219
renderinfo: Default::default(),
219220
ty_substs: Default::default(),
220221
lt_substs: Default::default(),
222+
export_map: export_map,
221223
};
222224
debug!("crate: {:?}", ctxt.map.krate());
223225

‎src/librustdoc/test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn run(input: &str,
8787
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
8888

8989
let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
90-
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
90+
let driver::ExpansionResult { defs, mut hir_forest, analysis, .. } = {
9191
phase_2_configure_and_expand(
9292
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
9393
).expect("phase_2_configure_and_expand aborted in rustdoc!")
@@ -110,6 +110,7 @@ pub fn run(input: &str,
110110
renderinfo: Default::default(),
111111
ty_substs: Default::default(),
112112
lt_substs: Default::default(),
113+
export_map: analysis.export_map,
113114
};
114115

115116
let mut v = RustdocVisitor::new(&ctx);

‎src/librustdoc/visit_ast.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8585
&krate.module,
8686
None);
8787
// attach the crate's exported macros to the top-level module:
88-
self.module.macros = krate.exported_macros.iter()
89-
.map(|def| self.visit_macro(def)).collect();
88+
let macro_exports: Vec<_> =
89+
krate.exported_macros.iter().map(|def| self.visit_macro(def)).collect();
90+
self.module.macros.extend(macro_exports);
9091
self.module.is_crate = true;
9192
}
9293

@@ -191,6 +192,28 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
191192
let item = self.cx.map.expect_item(i.id);
192193
self.visit_item(item, None, &mut om);
193194
}
195+
if let Some(exports) = self.cx.export_map.get(&id) {
196+
for export in exports {
197+
if let Def::Macro(def_id) = export.def {
198+
if def_id.krate == LOCAL_CRATE {
199+
continue // These are `krate.exported_macros`, handled in `self.visit()`.
200+
}
201+
let def = self.cx.sess().cstore.load_macro(def_id, self.cx.sess());
202+
// FIXME(jseyfried) merge with `self.visit_macro()`
203+
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
204+
om.macros.push(Macro {
205+
id: def.id,
206+
attrs: def.attrs.clone().into(),
207+
name: def.ident.name,
208+
whence: def.span,
209+
matchers: matchers,
210+
stab: self.stability(def.id),
211+
depr: self.deprecation(def.id),
212+
imported_from: def.imported_from.map(|ident| ident.name),
213+
})
214+
}
215+
}
216+
}
194217
om
195218
}
196219

0 commit comments

Comments
 (0)
Please sign in to comment.