]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/json/conversions.rs
Rename RealFileName::Named to LocalPath and Devirtualized to Remapped
[rust.git] / src / librustdoc / json / conversions.rs
index 10d5b9807b0104b3933347bc544a1cbaf2773f90..88e369e1babc216fd5362d5408b9b97c3ff584ad 100644 (file)
@@ -10,7 +10,6 @@
 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::*;
@@ -34,10 +33,18 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
                 did.map(|did| (link.clone(), from_def_id(did)))
             })
             .collect();
-        let clean::Item { span, name, attrs, kind, visibility, def_id } = item;
-        let inner = match *kind {
+        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),
@@ -45,12 +52,8 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
             name: name.map(|sym| sym.to_string()),
             span: self.convert_span(span),
             visibility: self.convert_visibility(visibility),
-            docs: attrs.collapsed_doc_value(),
-            attrs: attrs
-                .other_attrs
-                .iter()
-                .map(rustc_ast_pretty::pprust::attribute_to_string)
-                .collect(),
+            docs,
+            attrs,
             deprecation: deprecation.map(from_deprecation),
             inner,
             links,
@@ -63,12 +66,7 @@ fn convert_span(&self, span: clean::Span) -> Option<Span> {
                 let hi = span.hi(self.sess());
                 let lo = span.lo(self.sess());
                 Some(Span {
-                    filename: match name {
-                        rustc_span::RealFileName::Named(path) => path,
-                        rustc_span::RealFileName::Devirtualized { local_path, virtual_name: _ } => {
-                            local_path
-                        }
-                    },
+                    filename: name.into_local_path(),
                     begin: (lo.line, lo.col.to_usize()),
                     end: (hi.line, hi.col.to_usize()),
                 })
@@ -172,10 +170,12 @@ fn from_tcx(kind: clean::TypeBindingKind, tcx: TyCtxt<'_>) -> Self {
     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)),
@@ -214,12 +214,6 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Sy
     }
 }
 
-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_;
@@ -422,7 +416,7 @@ fn from_tcx(bare_decl: clean::BareFunctionDecl, tcx: TyCtxt<'_>) -> Self {
 
 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
@@ -454,16 +448,17 @@ fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
 
 impl FromWithTcx<clean::Impl> for Impl {
     fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self {
+        let provided_trait_methods = impl_.provided_trait_methods(tcx);
         let clean::Impl {
             unsafety,
             generics,
-            provided_trait_methods,
             trait_,
             for_,
             items,
             negative_polarity,
             synthetic,
             blanket_impl,
+            span: _span,
         } = impl_;
         Impl {
             is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,