Skip to content

Commit 16a4ad7

Browse files
committed
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.
1 parent 4ed8cf4 commit 16a4ad7

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

src/librustdoc/formats/cache.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ impl DocFolder for CacheBuilder<'_, '_> {
305305
| clean::MacroItem(..)
306306
| clean::ProcMacroItem(..)
307307
| clean::VariantItem(..) => {
308+
use rustc_data_structures::fx::IndexEntry as Entry;
308309
if !self.cache.stripped_mod {
309310
// Re-exported items mean that the same id can show up twice
310311
// in the rustdoc ast that we're looking at. We know,
@@ -313,15 +314,15 @@ impl DocFolder for CacheBuilder<'_, '_> {
313314
// paths map if there was already an entry present and we're
314315
// not a public item.
315316
let item_def_id = item.item_id.expect_def_id();
316-
if !self.cache.paths.contains_key(&item_def_id)
317-
|| self
318-
.cache
319-
.effective_visibilities
320-
.is_directly_public(self.tcx, item_def_id)
321-
{
322-
self.cache
323-
.paths
324-
.insert(item_def_id, (self.cache.stack.clone(), item.type_()));
317+
match self.cache.paths.entry(item_def_id) {
318+
Entry::Vacant(entry) => {
319+
entry.insert((self.cache.stack.clone(), item.type_()));
320+
}
321+
Entry::Occupied(mut entry) => {
322+
if entry.get().0.len() > self.cache.stack.len() {
323+
entry.insert((self.cache.stack.clone(), item.type_()));
324+
}
325+
}
325326
}
326327
}
327328
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Test case for [134702]
2+
//!
3+
//! [134702]: https://github.com/rust-lang/rust/issues/134702
4+
#![crate_name = "foo"]
5+
6+
pub mod inside1 {
7+
pub use self::inner::Inside1;
8+
mod inner {
9+
pub struct Inside1;
10+
impl Inside1 {
11+
pub fn stuff(self) {}
12+
}
13+
}
14+
}
15+
16+
pub mod inside2 {
17+
pub use self::inner::Inside2;
18+
mod inner {
19+
pub struct Inside2;
20+
impl Inside2 {
21+
pub fn stuff(self) {}
22+
}
23+
}
24+
}
25+
26+
pub mod nested {
27+
//! [Inside1] [Inside2]
28+
//@ has foo/nested/index.html '//a[@href="../struct.Inside1.html"]' 'Inside1'
29+
//@ has foo/nested/index.html '//a[@href="../struct.Inside2.html"]' 'Inside2'
30+
//! [Inside1::stuff] [Inside2::stuff]
31+
//@ has foo/nested/index.html '//a[@href="../struct.Inside1.html#method.stuff"]' 'Inside1::stuff'
32+
//@ has foo/nested/index.html '//a[@href="../struct.Inside2.html#method.stuff"]' 'Inside2::stuff'
33+
use crate::inside1::Inside1;
34+
use crate::inside2::Inside2;
35+
}
36+
37+
#[doc(inline)]
38+
pub use inside1::Inside1;
39+
#[doc(inline)]
40+
pub use inside2::Inside2;

0 commit comments

Comments
 (0)