about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2021-11-19 17:51:45 -0500
committerNoah Lev <camelidcamel@gmail.com>2021-11-19 17:55:40 -0500
commit331465a867fd450939d23d6ebd0580fc0ef18059 (patch)
treed2c353a71d28b2365a22f20d9cf961f8faf6491d
parent548c1088eff51fd92ad94d56b8c5b2d48b7088f0 (diff)
downloadrust-331465a867fd450939d23d6ebd0580fc0ef18059.tar.gz
rust-331465a867fd450939d23d6ebd0580fc0ef18059.zip
rustdoc: Pass DocContext to `Cache::populate`
This will allow removing `Crate.externs`.
-rw-r--r--src/librustdoc/core.rs6
-rw-r--r--src/librustdoc/formats/cache.rs33
2 files changed, 18 insertions, 21 deletions
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index a331f4cf3e6..c58310947d2 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -508,14 +508,12 @@ crate fn run_global_ctxt(
         rustc_errors::FatalError.raise();
     }
 
-    let render_options = ctxt.render_options;
-    let mut cache = ctxt.cache;
-    krate = tcx.sess.time("create_format_cache", || cache.populate(krate, tcx, &render_options));
+    krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
 
     // The main crate doc comments are always collapsed.
     krate.collapsed = true;
 
-    (krate, render_options, cache)
+    (krate, ctxt.render_options, ctxt.cache)
 }
 
 /// Due to <https://github.com/rust-lang/rust/pull/73566>,
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index 05d8b643f50..b6808732ad0 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -8,6 +8,7 @@ use rustc_span::symbol::sym;
 
 use crate::clean::{self, ItemId, PrimitiveType};
 use crate::config::RenderOptions;
+use crate::core::DocContext;
 use crate::fold::DocFolder;
 use crate::formats::item_type::ItemType;
 use crate::formats::Impl;
@@ -136,15 +137,13 @@ impl Cache {
 
     /// Populates the `Cache` with more data. The returned `Crate` will be missing some data that was
     /// in `krate` due to the data being moved into the `Cache`.
-    crate fn populate(
-        &mut self,
-        mut krate: clean::Crate,
-        tcx: TyCtxt<'_>,
-        render_options: &RenderOptions,
-    ) -> clean::Crate {
+    crate fn populate(cx: &mut DocContext<'_>, mut krate: clean::Crate) -> clean::Crate {
+        let tcx = cx.tcx;
+        let render_options = &cx.render_options;
+
         // Crawl the crate to build various caches used for the output
-        debug!(?self.crate_version);
-        self.traits = krate.external_traits.take();
+        debug!(?cx.cache.crate_version);
+        cx.cache.traits = krate.external_traits.take();
         let RenderOptions { extern_html_root_takes_precedence, output: dst, .. } = render_options;
 
         // Cache where all our extern crates are located
@@ -154,28 +153,28 @@ impl Cache {
             let extern_url =
                 render_options.extern_html_root_urls.get(&*name.as_str()).map(|u| &**u);
             let location = e.location(extern_url, *extern_html_root_takes_precedence, dst, tcx);
-            self.extern_locations.insert(e.crate_num, location);
-            self.external_paths.insert(e.def_id(), (vec![name.to_string()], ItemType::Module));
+            cx.cache.extern_locations.insert(e.crate_num, location);
+            cx.cache.external_paths.insert(e.def_id(), (vec![name.to_string()], ItemType::Module));
         }
 
         // FIXME: avoid this clone (requires implementing Default manually)
-        self.primitive_locations = PrimitiveType::primitive_locations(tcx).clone();
-        for (prim, &def_id) in &self.primitive_locations {
+        cx.cache.primitive_locations = PrimitiveType::primitive_locations(tcx).clone();
+        for (prim, &def_id) in &cx.cache.primitive_locations {
             let crate_name = tcx.crate_name(def_id.krate);
             // Recall that we only allow primitive modules to be at the root-level of the crate.
             // If that restriction is ever lifted, this will have to include the relative paths instead.
-            self.external_paths.insert(
+            cx.cache.external_paths.insert(
                 def_id,
                 (vec![crate_name.to_string(), prim.as_sym().to_string()], ItemType::Primitive),
             );
         }
 
-        krate = CacheBuilder { tcx, cache: self }.fold_crate(krate);
+        krate = CacheBuilder { tcx, cache: &mut cx.cache }.fold_crate(krate);
 
-        for (trait_did, dids, impl_) in self.orphan_trait_impls.drain(..) {
-            if self.traits.contains_key(&trait_did) {
+        for (trait_did, dids, impl_) in cx.cache.orphan_trait_impls.drain(..) {
+            if cx.cache.traits.contains_key(&trait_did) {
                 for did in dids {
-                    self.impls.entry(did).or_default().push(impl_.clone());
+                    cx.cache.impls.entry(did).or_default().push(impl_.clone());
                 }
             }
         }