summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/json/mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
commit2ff14448863ac1a1dd9533461708e29aae170c2d (patch)
tree85b9fea2bbfe3f06473cfa381eed11f273b57c5c /src/librustdoc/json/mod.rs
parentAdding debian version 1.64.0+dfsg1-1. (diff)
downloadrustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz
rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/json/mod.rs')
-rw-r--r--src/librustdoc/json/mod.rs38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index 6364d00d0..5e8f5f6fe 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -5,6 +5,7 @@
//! docs for usage and details.
mod conversions;
+mod import_finder;
use std::cell::RefCell;
use std::fs::{create_dir_all, File};
@@ -12,7 +13,7 @@ use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::rc::Rc;
-use rustc_data_structures::fx::FxHashMap;
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::DefId;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
@@ -39,6 +40,7 @@ pub(crate) struct JsonRenderer<'tcx> {
/// The directory where the blob will be written to.
out_path: PathBuf,
cache: Rc<Cache>,
+ imported_items: FxHashSet<DefId>,
}
impl<'tcx> JsonRenderer<'tcx> {
@@ -99,6 +101,7 @@ impl<'tcx> JsonRenderer<'tcx> {
}
fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
+ debug!("Adding foreign trait items");
Rc::clone(&self.cache)
.traits
.iter()
@@ -106,7 +109,10 @@ impl<'tcx> JsonRenderer<'tcx> {
// only need to synthesize items for external traits
if !id.is_local() {
let trait_item = &trait_item.trait_;
- trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
+ for item in &trait_item.items {
+ trace!("Adding subitem to {id:?}: {:?}", item.item_id);
+ self.item(item.clone()).unwrap();
+ }
let item_id = from_item_id(id.into(), self.tcx);
Some((
item_id.clone(),
@@ -157,12 +163,16 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer");
+
+ let (krate, imported_items) = import_finder::get_imports(krate);
+
Ok((
JsonRenderer {
tcx,
index: Rc::new(RefCell::new(FxHashMap::default())),
out_path: options.output,
cache: Rc::new(cache),
+ imported_items,
},
krate,
))
@@ -176,7 +186,9 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
/// the hashmap because certain items (traits and types) need to have their mappings for trait
/// implementations filled out before they're inserted.
fn item(&mut self, item: clean::Item) -> Result<(), Error> {
- trace!("rendering {} {:?}", item.type_(), item.name);
+ let item_type = item.type_();
+ let item_name = item.name;
+ trace!("rendering {} {:?}", item_type, item_name);
// Flatten items that recursively store other items. We include orphaned items from
// stripped modules and etc that are otherwise reachable.
@@ -209,11 +221,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
}
types::ItemEnum::Method(_)
+ | types::ItemEnum::Module(_)
| types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. }
| types::ItemEnum::PrimitiveType(_) => true,
- types::ItemEnum::Module(_)
- | types::ItemEnum::ExternCrate { .. }
+ types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_)
| types::ItemEnum::Variant(_)
@@ -245,6 +257,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
}
}
+ trace!("done rendering {} {:?}", item_type, item_name);
Ok(())
}
@@ -255,14 +268,20 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
fn after_krate(&mut self) -> Result<(), Error> {
debug!("Done with crate");
+ debug!("Adding Primitve impls");
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
self.get_impls(*primitive);
}
let e = ExternalCrate { crate_num: LOCAL_CRATE };
+ // FIXME(adotinthevoid): Remove this, as it's not consistant with not
+ // inlining foreign items.
+ let foreign_trait_items = self.get_trait_items();
let mut index = (*self.index).clone().into_inner();
- index.extend(self.get_trait_items());
+ index.extend(foreign_trait_items);
+
+ debug!("Constructing Output");
// This needs to be the default HashMap for compatibility with the public interface for
// rustdoc-json-types
#[allow(rustc::default_hash_types)]
@@ -274,10 +293,9 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
paths: self
.cache
.paths
- .clone()
- .into_iter()
- .chain(self.cache.external_paths.clone().into_iter())
- .map(|(k, (path, kind))| {
+ .iter()
+ .chain(&self.cache.external_paths)
+ .map(|(&k, &(ref path, kind))| {
(
from_item_id(k.into(), self.tcx),
types::ItemSummary {