]> git.lizzy.rs Git - rust.git/commitdiff
add a rustc_resolve::Resolver to DocContext
authorQuietMisdreavus <grey@quietmisdreavus.net>
Thu, 21 Dec 2017 21:16:29 +0000 (15:16 -0600)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 22 Jan 2018 09:51:28 +0000 (15:21 +0530)
src/librustdoc/clean/mod.rs
src/librustdoc/core.rs
src/librustdoc/visit_ast.rs
src/librustdoc/visit_lib.rs

index cc75664cacbcce66745e3a6a0f8e630974feb165..6b58decd0b5d810277a6708543c6658f20e12cd3 100644 (file)
@@ -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;
 
index 6cbbe1fdf44fae5d7d1e9f04afbde74cb74a0266..b094567b15ea5f143c98359d8b0e480b59422a31 100644 (file)
@@ -20,6 +20,7 @@
 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 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(),
index 1cb52d735bb18317d8c81029f2496b507d32de20..23a2208292a360eb5cf8002cd655d3dddca9b93c 100644 (file)
 // 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);
index 2fd47fa0a6d0aba6c5fcbde9a18bee76ad3c2d46..7da0a7bfe6ea815190b3b9d1d44ab401456caea8 100644 (file)
@@ -22,8 +22,8 @@
 
 /// 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(),