]> git.lizzy.rs Git - rust.git/commitdiff
Get rid of doctree::ForeignItem
authorJoshua Nelson <jyn514@gmail.com>
Sun, 22 Nov 2020 19:03:02 +0000 (14:03 -0500)
committerJoshua Nelson <jyn514@gmail.com>
Tue, 24 Nov 2020 14:54:53 +0000 (09:54 -0500)
src/librustdoc/clean/mod.rs
src/librustdoc/doctree.rs
src/librustdoc/visit_ast.rs

index e76ca1022a943f147af72b19564c5ec5232a33d4..c0786c1c127b8369dfa87ae75ae7adfe0f0783bd 100644 (file)
@@ -2186,11 +2186,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
     }
 }
 
-impl Clean<Item> for doctree::ForeignItem<'_> {
+impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
     fn clean(&self, cx: &DocContext<'_>) -> Item {
-        let kind = match self.kind {
+        let (item, renamed) = self;
+        let kind = match item.kind {
             hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
-                let abi = cx.tcx.hir().get_foreign_abi(self.id);
+                let abi = cx.tcx.hir().get_foreign_abi(item.hir_id);
                 let (generics, decl) =
                     enter_impl_trait(cx, || (generics.clean(cx), (&**decl, &names[..]).clean(cx)));
                 let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
@@ -2207,15 +2208,13 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
                     ret_types,
                 })
             }
-            hir::ForeignItemKind::Static(ref ty, mutbl) => ForeignStaticItem(Static {
-                type_: ty.clean(cx),
-                mutability: *mutbl,
-                expr: String::new(),
-            }),
+            hir::ForeignItemKind::Static(ref ty, mutability) => {
+                ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: String::new() })
+            }
             hir::ForeignItemKind::Type => ForeignTypeItem,
         };
 
-        Item::from_hir_id_and_parts(self.id, Some(self.name), kind, cx)
+        Item::from_hir_id_and_parts(item.hir_id, Some(renamed.unwrap_or(item.ident).name), kind, cx)
     }
 }
 
index 4d2fe04123bc2489c982d8d4da0c2af3ac5f2052..1ceaed45ea9cf370fcd8035fa437b377da0e4091 100644 (file)
@@ -23,7 +23,7 @@
     // (item, renamed)
     crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
     crate traits: Vec<Trait<'hir>>,
-    crate foreigns: Vec<ForeignItem<'hir>>,
+    crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
     crate macros: Vec<Macro>,
     crate proc_macros: Vec<ProcMacro>,
     crate is_crate: bool,
@@ -87,12 +87,6 @@ impl Module<'hir> {
     crate id: hir::HirId,
 }
 
-crate struct ForeignItem<'hir> {
-    crate id: hir::HirId,
-    crate name: Symbol,
-    crate kind: &'hir hir::ForeignItemKind<'hir>,
-}
-
 // For Macro we store the DefId instead of the NodeId, since we also create
 // these imported macro_rules (which only have a DUMMY_NODE_ID).
 crate struct Macro {
index 37050a57ca0173c6c0b0b756ce4fc0b68a34f680..03e31da3711059dce5cdab066542495f0c11da01 100644 (file)
@@ -418,15 +418,9 @@ fn visit_foreign_item(
         om: &mut Module<'tcx>,
     ) {
         // If inlining we only want to include public functions.
-        if self.inlining && !item.vis.node.is_pub() {
-            return;
+        if !self.inlining || item.vis.node.is_pub() {
+            om.foreigns.push((item, renamed));
         }
-
-        om.foreigns.push(ForeignItem {
-            id: item.hir_id,
-            name: renamed.unwrap_or(item.ident).name,
-            kind: &item.kind,
-        });
     }
 
     // Convert each `exported_macro` into a doc item.