Skip to content

Commit 76f8316

Browse files
QuietMisdreavusManishearth
authored andcommitted
add a rustc_resolve::Resolver to DocContext
1 parent d9c1a17 commit 76f8316

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub struct Crate {
124124
pub masked_crates: FxHashSet<CrateNum>,
125125
}
126126

127-
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
127+
impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> {
128128
fn clean(&self, cx: &DocContext) -> Crate {
129129
use ::visit_lib::LibEmbargoVisitor;
130130

src/librustdoc/core.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::lint;
2020
use rustc::util::nodemap::FxHashMap;
2121
use rustc_trans;
2222
use rustc_resolve as resolve;
23+
use rustc_metadata::creader::CrateLoader;
2324
use rustc_metadata::cstore::CStore;
2425

2526
use syntax::codemap;
@@ -43,8 +44,9 @@ pub use rustc::session::search_paths::SearchPaths;
4344

4445
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
4546

46-
pub struct DocContext<'a, 'tcx: 'a> {
47+
pub struct DocContext<'a, 'tcx: 'a, 'rcx> {
4748
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
49+
pub resolver: resolve::Resolver<'rcx>,
4850
pub populated_all_crate_impls: Cell<bool>,
4951
// Note that external items for which `doc(hidden)` applies to are shown as
5052
// non-reachable while local items aren't. This is because we're reusing
@@ -67,7 +69,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
6769
pub lt_substs: RefCell<FxHashMap<DefId, clean::Lifetime>>,
6870
}
6971

70-
impl<'a, 'tcx> DocContext<'a, 'tcx> {
72+
impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> {
7173
pub fn sess(&self) -> &session::Session {
7274
&self.tcx.sess
7375
}
@@ -160,7 +162,13 @@ pub fn run_core(search_paths: SearchPaths,
160162

161163
let name = ::rustc_trans_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
162164

163-
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
165+
let driver::ExpansionResult {
166+
expanded_crate,
167+
defs,
168+
analysis,
169+
resolutions,
170+
mut hir_forest
171+
} = {
164172
let result = driver::phase_2_configure_and_expand(&sess,
165173
&cstore,
166174
krate,
@@ -173,6 +181,8 @@ pub fn run_core(search_paths: SearchPaths,
173181
};
174182

175183
let arenas = AllArenas::new();
184+
let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
185+
let resolver_arenas = resolve::Resolver::arenas();
176186
let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);
177187
let output_filenames = driver::build_output_filenames(&input,
178188
&None,
@@ -205,8 +215,19 @@ pub fn run_core(search_paths: SearchPaths,
205215
.collect()
206216
};
207217

218+
// Set up a Resolver so that the doc cleaning can look up paths in the docs
219+
let mut resolver = resolve::Resolver::new(&sess,
220+
&*cstore,
221+
&expanded_crate,
222+
&name,
223+
resolve::MakeGlobMap::No,
224+
&mut crate_loader,
225+
&resolver_arenas);
226+
resolver.resolve_crate(&expanded_crate);
227+
208228
let ctxt = DocContext {
209229
tcx,
230+
resolver,
210231
populated_all_crate_impls: Cell::new(false),
211232
access_levels: RefCell::new(access_levels),
212233
external_traits: Default::default(),

src/librustdoc/visit_ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ use doctree::*;
4040
// also, is there some reason that this doesn't use the 'visit'
4141
// framework from syntax?
4242

43-
pub struct RustdocVisitor<'a, 'tcx: 'a> {
43+
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
4444
cstore: &'tcx CrateStore,
4545
pub module: Module,
4646
pub attrs: hir::HirVec<ast::Attribute>,
47-
pub cx: &'a core::DocContext<'a, 'tcx>,
47+
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
4848
view_item_stack: FxHashSet<ast::NodeId>,
4949
inlining: bool,
5050
/// Is the current module and all of its parents public?
5151
inside_public_path: bool,
5252
reexported_macros: FxHashSet<DefId>,
5353
}
5454

55-
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
55+
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
5656
pub fn new(cstore: &'tcx CrateStore,
57-
cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
57+
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
5858
// If the root is re-exported, terminate all recursion.
5959
let mut stack = FxHashSet();
6060
stack.insert(ast::CRATE_NODE_ID);

src/librustdoc/visit_lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use clean::{AttributesExt, NestedAttributesExt};
2222

2323
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
2424
/// specific rustdoc annotations into account (i.e. `doc(hidden)`)
25-
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> {
26-
cx: &'a ::core::DocContext<'b, 'tcx>,
25+
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'a> {
26+
cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>,
2727
// Accessibility levels for reachable nodes
2828
access_levels: RefMut<'a, AccessLevels<DefId>>,
2929
// Previous accessibility level, None means unreachable
@@ -32,8 +32,8 @@ pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> {
3232
visited_mods: FxHashSet<DefId>,
3333
}
3434

35-
impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> {
36-
pub fn new(cx: &'a ::core::DocContext<'b, 'tcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx> {
35+
impl<'a, 'b, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
36+
pub fn new(cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
3737
LibEmbargoVisitor {
3838
cx,
3939
access_levels: cx.access_levels.borrow_mut(),

0 commit comments

Comments
 (0)