diff options
| author | QuietMisdreavus <grey@quietmisdreavus.net> | 2017-12-21 15:16:29 -0600 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2018-01-22 15:21:28 +0530 |
| commit | 76f831647ade4a5e82244bd4d19da308478cc83d (patch) | |
| tree | eadeb45ec493e9c9f16562564aed55a105edd099 | |
| parent | d9c1a17eecf7539368e541958f95562a81fd600a (diff) | |
| download | rust-76f831647ade4a5e82244bd4d19da308478cc83d.tar.gz rust-76f831647ade4a5e82244bd4d19da308478cc83d.zip | |
add a rustc_resolve::Resolver to DocContext
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 27 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/visit_lib.rs | 8 |
4 files changed, 33 insertions, 12 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cc75664cacb..6b58decd0b5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -124,7 +124,7 @@ pub struct Crate { pub masked_crates: FxHashSet<CrateNum>, } -impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> { +impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> { fn clean(&self, cx: &DocContext) -> Crate { use ::visit_lib::LibEmbargoVisitor; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 6cbbe1fdf44..b094567b15e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -20,6 +20,7 @@ use rustc::lint; use rustc::util::nodemap::FxHashMap; use rustc_trans; use rustc_resolve as resolve; +use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use syntax::codemap; @@ -43,8 +44,9 @@ pub use rustc::session::search_paths::SearchPaths; pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>; -pub struct DocContext<'a, 'tcx: 'a> { +pub struct DocContext<'a, 'tcx: 'a, 'rcx> { pub tcx: TyCtxt<'a, 'tcx, 'tcx>, + pub resolver: resolve::Resolver<'rcx>, pub populated_all_crate_impls: Cell<bool>, // Note that external items for which `doc(hidden)` applies to are shown as // non-reachable while local items aren't. This is because we're reusing @@ -67,7 +69,7 @@ pub struct DocContext<'a, 'tcx: 'a> { pub lt_substs: RefCell<FxHashMap<DefId, clean::Lifetime>>, } -impl<'a, 'tcx> DocContext<'a, 'tcx> { +impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { pub fn sess(&self) -> &session::Session { &self.tcx.sess } @@ -160,7 +162,13 @@ pub fn run_core(search_paths: SearchPaths, let name = ::rustc_trans_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input); - let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = { + let driver::ExpansionResult { + expanded_crate, + defs, + analysis, + resolutions, + mut hir_forest + } = { let result = driver::phase_2_configure_and_expand(&sess, &cstore, krate, @@ -173,6 +181,8 @@ pub fn run_core(search_paths: SearchPaths, }; let arenas = AllArenas::new(); + let mut crate_loader = CrateLoader::new(&sess, &cstore, &name); + let resolver_arenas = resolve::Resolver::arenas(); let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs); let output_filenames = driver::build_output_filenames(&input, &None, @@ -205,8 +215,19 @@ pub fn run_core(search_paths: SearchPaths, .collect() }; + // Set up a Resolver so that the doc cleaning can look up paths in the docs + let mut resolver = resolve::Resolver::new(&sess, + &*cstore, + &expanded_crate, + &name, + resolve::MakeGlobMap::No, + &mut crate_loader, + &resolver_arenas); + resolver.resolve_crate(&expanded_crate); + let ctxt = DocContext { tcx, + resolver, populated_all_crate_impls: Cell::new(false), access_levels: RefCell::new(access_levels), external_traits: Default::default(), diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 1cb52d735bb..23a2208292a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -40,11 +40,11 @@ use doctree::*; // also, is there some reason that this doesn't use the 'visit' // framework from syntax? -pub struct RustdocVisitor<'a, 'tcx: 'a> { +pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> { cstore: &'tcx CrateStore, pub module: Module, pub attrs: hir::HirVec<ast::Attribute>, - pub cx: &'a core::DocContext<'a, 'tcx>, + pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, view_item_stack: FxHashSet<ast::NodeId>, inlining: bool, /// Is the current module and all of its parents public? @@ -52,9 +52,9 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> { reexported_macros: FxHashSet<DefId>, } -impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { +impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { pub fn new(cstore: &'tcx CrateStore, - cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> { + cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> { // If the root is re-exported, terminate all recursion. let mut stack = FxHashSet(); stack.insert(ast::CRATE_NODE_ID); diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 2fd47fa0a6d..7da0a7bfe6e 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -22,8 +22,8 @@ use clean::{AttributesExt, NestedAttributesExt}; /// Similar to `librustc_privacy::EmbargoVisitor`, but also takes /// specific rustdoc annotations into account (i.e. `doc(hidden)`) -pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> { - cx: &'a ::core::DocContext<'b, 'tcx>, +pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'a> { + cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>, // Accessibility levels for reachable nodes access_levels: RefMut<'a, AccessLevels<DefId>>, // Previous accessibility level, None means unreachable @@ -32,8 +32,8 @@ pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> { visited_mods: FxHashSet<DefId>, } -impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> { - pub fn new(cx: &'a ::core::DocContext<'b, 'tcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> { + pub fn new(cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> { LibEmbargoVisitor { cx, access_levels: cx.access_levels.borrow_mut(), |
