diff options
| author | bors <bors@rust-lang.org> | 2024-04-18 21:23:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-18 21:23:15 +0000 |
| commit | e3181b091e88321f5ea149afed6db0edf0a4f37b (patch) | |
| tree | 6ff2feb52920f80ff744c832385c5da2b126581a /src/librustdoc/formats/cache.rs | |
| parent | 3412f0174934778dd803081dc7c4b5864309350f (diff) | |
| parent | 226c77d0a4397d19542fd9e752fa75247befe9e0 (diff) | |
| download | rust-e3181b091e88321f5ea149afed6db0edf0a4f37b.tar.gz rust-e3181b091e88321f5ea149afed6db0edf0a4f37b.zip | |
Auto merge of #119912 - notriddle:notriddle/reexport-dedup, r=GuillaumeGomez
rustdoc-search: single result for items with multiple paths Part of #15723 Preview: https://notriddle.com/rustdoc-html-demo-9/reexport-dup/std/index.html?search=hashmap This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`. It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
Diffstat (limited to 'src/librustdoc/formats/cache.rs')
| -rw-r--r-- | src/librustdoc/formats/cache.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 11fc99eb511..a3b88a880f2 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -346,16 +346,28 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { { let desc = short_markdown_summary(&item.doc_value(), &item.link_names(self.cache)); + // For searching purposes, a re-export is a duplicate if: + // + // - It's either an inline, or a true re-export + // - It's got the same name + // - Both of them have the same exact path + let defid = (match &*item.kind { + &clean::ItemKind::ImportItem(ref import) => import.source.did, + _ => None, + }) + .or_else(|| item.item_id.as_def_id()); // In case this is a field from a tuple struct, we don't add it into // the search index because its name is something like "0", which is // not useful for rustdoc search. self.cache.search_index.push(IndexItem { ty, + defid, name: s, path: join_with_double_colon(path), desc, parent, parent_idx: None, + exact_path: None, impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) = self.cache.parent_stack.last() { |
