use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
-use rustc_span::edition::Edition;
use rustdoc_json_types as types;
use crate::formats::cache::Cache;
use crate::formats::FormatRenderer;
use crate::html::render::cache::ExternalLocation;
-use crate::json::conversions::from_def_id;
+use crate::json::conversions::{from_def_id, IntoWithTcx};
#[derive(Clone)]
crate struct JsonRenderer<'tcx> {
.last()
.map(Clone::clone),
visibility: types::Visibility::Public,
- inner: types::ItemEnum::Trait(trait_item.clone().into()),
- source: None,
+ inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
+ span: None,
docs: Default::default(),
links: Default::default(),
attrs: Default::default(),
"json"
}
+ const RUN_ON_MODULE: bool = false;
+
fn init(
krate: clean::Crate,
options: RenderOptions,
- _edition: Edition,
cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, clean::Crate), Error> {
e.impls = self.get_impls(id)
}
let removed = self.index.borrow_mut().insert(from_def_id(id), new_item.clone());
+
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
- // to make sure the items are unique.
+ // to make sure the items are unique. The main place this happens is when an item, is
+ // reexported in more than one place. See `rustdoc-json/reexport/in_root_and_mod`
if let Some(old_item) = removed {
assert_eq!(old_item, new_item);
}
Ok(())
}
- fn mod_item_in(&mut self, item: &clean::Item, _module_name: &str) -> Result<(), Error> {
- use clean::types::ItemKind::*;
- if let ModuleItem(m) = &*item.kind {
- for item in &m.items {
- match &*item.kind {
- // These don't have names so they don't get added to the output by default
- ImportItem(_) => self.item(item.clone()).unwrap(),
- ExternCrateItem { .. } => self.item(item.clone()).unwrap(),
- ImplItem(i) => i.items.iter().for_each(|i| self.item(i.clone()).unwrap()),
- _ => {}
- }
- }
- }
- self.item(item.clone()).unwrap();
- Ok(())
- }
-
- fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> {
- Ok(())
+ fn mod_item_in(&mut self, _item: &clean::Item) -> Result<(), Error> {
+ unreachable!("RUN_ON_MODULE = false should never call mod_item_in")
}
- fn after_krate(
- &mut self,
- _krate: &clean::Crate,
- _diag: &rustc_errors::Handler,
- ) -> Result<(), Error> {
+ fn after_krate(&mut self) -> Result<(), Error> {
debug!("Done with crate");
let mut index = (*self.index).clone().into_inner();
index.extend(self.get_trait_items());
.map(|(k, (path, kind))| {
(
from_def_id(k),
- types::ItemSummary { crate_id: k.krate.as_u32(), path, kind: kind.into() },
+ types::ItemSummary {
+ crate_id: k.krate.as_u32(),
+ path,
+ kind: kind.into_tcx(self.tcx),
+ },
)
})
.collect(),
)
})
.collect(),
- format_version: 4,
+ format_version: 5,
};
let mut p = self.out_path.clone();
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());