From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- src/librustdoc/json/mod.rs | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/librustdoc/json/mod.rs') diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 6364d00d0..d13efe6c1 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, + imported_items: FxHashSet, } impl<'tcx> JsonRenderer<'tcx> { @@ -99,14 +101,17 @@ 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() .filter_map(|(&id, trait_item)| { // 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 +162,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 +185,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. @@ -207,13 +218,16 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { u.impls = self.get_impls(item_id.expect_def_id()); false } + types::ItemEnum::Primitive(ref mut p) => { + p.impls = self.get_impls(item_id.expect_def_id()); + false + } types::ItemEnum::Method(_) + | types::ItemEnum::Module(_) | types::ItemEnum::AssocConst { .. } - | types::ItemEnum::AssocType { .. } - | types::ItemEnum::PrimitiveType(_) => true, - types::ItemEnum::Module(_) - | types::ItemEnum::ExternCrate { .. } + | types::ItemEnum::AssocType { .. } => true, + types::ItemEnum::ExternCrate { .. } | types::ItemEnum::Import(_) | types::ItemEnum::StructField(_) | types::ItemEnum::Variant(_) @@ -245,6 +259,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { } } + trace!("done rendering {} {:?}", item_type, item_name); Ok(()) } @@ -255,14 +270,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 +295,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 { -- cgit v1.2.3