use rustc_hir::def::CtorKind;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
-use rustc_span::symbol::Symbol;
use rustc_span::Pos;
use rustdoc_json_types::*;
impl JsonRenderer<'_> {
pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
let deprecation = item.deprecation(self.tcx);
- let clean::Item { span, name, attrs, kind, visibility, def_id } = item;
- let inner = match *kind {
+ let links = self
+ .cache
+ .intra_doc_links
+ .get(&item.def_id)
+ .into_iter()
+ .flatten()
+ .filter_map(|clean::ItemLink { link, did, .. }| {
+ did.map(|did| (link.clone(), from_def_id(did)))
+ })
+ .collect();
+ let docs = item.attrs.collapsed_doc_value();
+ let attrs = item
+ .attrs
+ .other_attrs
+ .iter()
+ .map(rustc_ast_pretty::pprust::attribute_to_string)
+ .collect();
+ let span = item.span(self.tcx);
+ let clean::Item { name, attrs: _, kind: _, visibility, def_id, cfg: _ } = item;
+ let inner = match *item.kind {
clean::StrippedItem(_) => return None,
- kind => from_clean_item_kind(kind, self.tcx, &name),
+ _ => from_clean_item(item, self.tcx),
};
Some(Item {
id: from_def_id(def_id),
name: name.map(|sym| sym.to_string()),
span: self.convert_span(span),
visibility: self.convert_visibility(visibility),
- docs: attrs.collapsed_doc_value(),
- links: attrs
- .links
- .into_iter()
- .filter_map(|clean::ItemLink { link, did, .. }| {
- did.map(|did| (link, from_def_id(did)))
- })
- .collect(),
- attrs: attrs
- .other_attrs
- .iter()
- .map(rustc_ast_pretty::pprust::attribute_to_string)
- .collect(),
+ docs,
+ attrs,
deprecation: deprecation.map(from_deprecation),
inner,
+ links,
})
}
Id(format!("{}:{}", did.krate.as_u32(), u32::from(did.index)))
}
-fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Symbol>) -> ItemEnum {
+fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
use clean::ItemKind::*;
- match item {
- ModuleItem(m) => ItemEnum::Module(m.into_tcx(tcx)),
+ let name = item.name;
+ let is_crate = item.is_crate();
+ match *item.kind {
+ ModuleItem(m) => ItemEnum::Module(Module { is_crate, items: ids(m.items) }),
ImportItem(i) => ItemEnum::Import(i.into_tcx(tcx)),
StructItem(s) => ItemEnum::Struct(s.into_tcx(tcx)),
UnionItem(u) => ItemEnum::Union(u.into_tcx(tcx)),
}
}
-impl FromWithTcx<clean::Module> for Module {
- fn from_tcx(module: clean::Module, _tcx: TyCtxt<'_>) -> Self {
- Module { is_crate: module.is_crate, items: ids(module.items) }
- }
-}
-
impl FromWithTcx<clean::Struct> for Struct {
fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self {
let clean::Struct { struct_type, generics, fields, fields_stripped } = struct_;
impl FromWithTcx<clean::FnDecl> for FnDecl {
fn from_tcx(decl: clean::FnDecl, tcx: TyCtxt<'_>) -> Self {
- let clean::FnDecl { inputs, output, c_variadic, attrs: _ } = decl;
+ let clean::FnDecl { inputs, output, c_variadic } = decl;
FnDecl {
inputs: inputs
.values
negative_polarity,
synthetic,
blanket_impl,
+ span: _span,
} = impl_;
Impl {
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,