about summary refs log tree commit diff
path: root/src/librustdoc/formats/cache.rs
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2024-12-26 15:43:43 -0700
committerMichael Howell <michael@notriddle.com>2024-12-26 15:46:36 -0700
commit16a4ad7d7b0d163f7be6803c786c3b83d42913bb (patch)
tree80e9db59e2add5f0b32b5ee121909bee8d147f79 /src/librustdoc/formats/cache.rs
parent4ed8cf4237a613a65670d1ea856fdb272e4cfc13 (diff)
downloadrust-16a4ad7d7b0d163f7be6803c786c3b83d42913bb.tar.gz
rust-16a4ad7d7b0d163f7be6803c786c3b83d42913bb.zip
rustdoc: use shorter paths as preferred canonical paths
This is a solution to the `std::sync::poison` linking problem,
and, in general, makes intra-doc links shorter and clearer.
Diffstat (limited to 'src/librustdoc/formats/cache.rs')
-rw-r--r--src/librustdoc/formats/cache.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index b63122565c4..361cea75f5e 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -305,6 +305,7 @@ impl DocFolder for CacheBuilder<'_, '_> {
             | clean::MacroItem(..)
             | clean::ProcMacroItem(..)
             | clean::VariantItem(..) => {
+                use rustc_data_structures::fx::IndexEntry as Entry;
                 if !self.cache.stripped_mod {
                     // Re-exported items mean that the same id can show up twice
                     // in the rustdoc ast that we're looking at. We know,
@@ -313,15 +314,15 @@ impl DocFolder for CacheBuilder<'_, '_> {
                     // paths map if there was already an entry present and we're
                     // not a public item.
                     let item_def_id = item.item_id.expect_def_id();
-                    if !self.cache.paths.contains_key(&item_def_id)
-                        || self
-                            .cache
-                            .effective_visibilities
-                            .is_directly_public(self.tcx, item_def_id)
-                    {
-                        self.cache
-                            .paths
-                            .insert(item_def_id, (self.cache.stack.clone(), item.type_()));
+                    match self.cache.paths.entry(item_def_id) {
+                        Entry::Vacant(entry) => {
+                            entry.insert((self.cache.stack.clone(), item.type_()));
+                        }
+                        Entry::Occupied(mut entry) => {
+                            if entry.get().0.len() > self.cache.stack.len() {
+                                entry.insert((self.cache.stack.clone(), item.type_()));
+                            }
+                        }
                     }
                 }
             }