about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2023-10-11 11:33:31 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2023-10-11 11:41:39 +0200
commita314707867141365e862624419b04788694b9169 (patch)
tree98a8f077e41f0ee89bfb487d284c800e535db275
parent6d05c430d2f0573bf98320bb1d2457a72ea1e67f (diff)
downloadrust-a314707867141365e862624419b04788694b9169.tar.gz
rust-a314707867141365e862624419b04788694b9169.zip
Prevent showing methods from blanket impls of not available foreign traits to show up in the search results
-rw-r--r--src/librustdoc/formats/cache.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index b916baecc14..36d32837ddf 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -310,7 +310,19 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
                                 for_: clean::Type::BorrowedRef { type_, .. },
                                 ..
                             } => type_.def_id(&self.cache),
-                            ParentStackItem::Impl { for_, .. } => for_.def_id(&self.cache),
+                            ParentStackItem::Impl { for_, trait_, .. } => {
+                                if let Some(trait_) = trait_ {
+                                    let trait_did = trait_.def_id();
+                                    // If this is a foreign trait impl but the trait documentation
+                                    // is not available, we should not allow the methods to show up
+                                    // in the search results.
+                                    if !trait_did.is_local() && self.tcx.is_private_dep(trait_did.krate)
+                                    {
+                                        return None;
+                                    }
+                                }
+                                for_.def_id(&self.cache)
+                            }
                             ParentStackItem::Type(item_id) => item_id.as_def_id(),
                         };
                         let path = did