From 5eba3f688cc6c2efc545c346675a5186da03e1fd Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 16 Feb 2023 16:49:28 -0700 Subject: [PATCH 1/2] rustdoc: hide `reference` methods in search index --- src/librustdoc/formats/cache.rs | 4 ++++ tests/rustdoc-js-std/reference-shrink.js | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/rustdoc-js-std/reference-shrink.js diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index b1db16cfe3cac..d25824a88ee8f 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -287,6 +287,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { } else { let last = self.cache.parent_stack.last().expect("parent_stack is empty 2"); let did = match &*last { + ParentStackItem::Impl { + for_: clean::Type::BorrowedRef { type_, .. }, + .. + } => type_.def_id(&self.cache), ParentStackItem::Impl { for_, .. } => for_.def_id(&self.cache), ParentStackItem::Type(item_id) => item_id.as_def_id(), }; diff --git a/tests/rustdoc-js-std/reference-shrink.js b/tests/rustdoc-js-std/reference-shrink.js new file mode 100644 index 0000000000000..f90be6d1bfd35 --- /dev/null +++ b/tests/rustdoc-js-std/reference-shrink.js @@ -0,0 +1,8 @@ +// exact-check + +const QUERY = 'reference::shrink'; + +const EXPECTED = { + // avoid including the method that's not going to be in the HTML + 'others': [], +}; From 0e3ae605bc245e0fb25e04c5f99d398d8a2b5c09 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 17 Feb 2023 10:35:19 -0700 Subject: [PATCH 2/2] Add comment explaining the search index tweak --- src/librustdoc/formats/cache.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index d25824a88ee8f..fe7081b571a5d 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -288,6 +288,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { let last = self.cache.parent_stack.last().expect("parent_stack is empty 2"); let did = match &*last { ParentStackItem::Impl { + // impl Trait for &T { fn method(self); } + // + // When generating a function index with the above shape, we want it + // associated with `T`, not with the primitive reference type. It should + // show up as `T::method`, rather than `reference::method`, in the search + // results page. for_: clean::Type::BorrowedRef { type_, .. }, .. } => type_.def_id(&self.cache),