about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRune Tynan <runetynan@gmail.com>2022-01-27 13:21:17 -0500
committerRune Tynan <runetynan@gmail.com>2022-01-28 10:45:20 -0500
commit2d2163bd3a4815c1a68de7b4246503977d99b21b (patch)
tree43fc2fb027285b6c9ed995f336fd3b8571145861
parentd90138bec8f406b5c01c6bed4c0e597df2f3b00f (diff)
downloadrust-2d2163bd3a4815c1a68de7b4246503977d99b21b.tar.gz
rust-2d2163bd3a4815c1a68de7b4246503977d99b21b.zip
Same code for ty and hir impl items
-rw-r--r--src/librustdoc/clean/mod.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index c6e66f0966a..a7eced29610 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1036,20 +1036,18 @@ impl Clean<Item> for hir::ImplItem<'_> {
                 }
             };
 
-            let what_rustc_thinks =
+            let mut what_rustc_thinks =
                 Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx);
-            let parent_item = cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(self.hir_id()));
-            if let hir::ItemKind::Impl(impl_) = &parent_item.kind {
-                if impl_.of_trait.is_some() {
-                    // Trait impl items always inherit the impl's visibility --
-                    // we don't want to show `pub`.
-                    Item { visibility: Inherited, ..what_rustc_thinks }
-                } else {
-                    what_rustc_thinks
-                }
-            } else {
-                panic!("found impl item with non-impl parent {:?}", parent_item);
+
+            let impl_ref = cx.tcx.parent(local_did).and_then(|did| cx.tcx.impl_trait_ref(did));
+
+            // Trait impl items always inherit the impl's visibility --
+            // we don't want to show `pub`.
+            if impl_ref.is_some() {
+                what_rustc_thinks.visibility = Inherited;
             }
+
+            what_rustc_thinks
         })
     }
 }
@@ -1204,16 +1202,18 @@ impl Clean<Item> for ty::AssocItem {
             }
         };
 
-        let mut output = Item::from_def_id_and_parts(self.def_id, Some(self.name), kind, cx);
+        let mut what_rustc_thinks =
+            Item::from_def_id_and_parts(self.def_id, Some(self.name), kind, cx);
 
-        // HACK: Override visibility for items in a trait implementation to match HIR
         let impl_ref = tcx.parent(self.def_id).and_then(|did| tcx.impl_trait_ref(did));
 
+        // Trait impl items always inherit the impl's visibility --
+        // we don't want to show `pub`.
         if impl_ref.is_some() {
-            output.visibility = Visibility::Inherited;
+            what_rustc_thinks.visibility = Visibility::Inherited;
         }
 
-        output
+        what_rustc_thinks
     }
 }