Skip to content

Commit d419cc7

Browse files
authored
Rollup merge of rust-lang#134806 - notriddle:notriddle/parent-path-is-better, r=GuillaumeGomez
rustdoc: use shorter paths as preferred canonical paths This is a solution to [the `std::sync::poison` linking problem](rust-lang#134692 (comment)), and, in general, makes intra-doc links shorter and clearer. > Done. This helped with the search, but not with the things like `MutexGuard`'s doc's reference to `Mutex::lock` being converted to the absolute (unstable) `std::sync::poison::Mutex` path. cc `@tgross35` r? `@GuillaumeGomez`
2 parents 72ef16f + da1c1c3 commit d419cc7

File tree

6 files changed

+80
-39
lines changed

6 files changed

+80
-39
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
}

tests/rustdoc-js-std/path-maxeditdistance.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const EXPECTED = [
1717
{ 'path': 'std::vec::IntoIter', 'name': 'into_iter' },
1818
{ 'path': 'std::vec::ExtractIf', 'name': 'into_iter' },
1919
{ 'path': 'std::vec::Splice', 'name': 'into_iter' },
20-
{ 'path': 'std::collections::vec_deque::VecDeque', 'name': 'iter' },
21-
{ 'path': 'std::collections::vec_deque::VecDeque', 'name': 'iter_mut' },
22-
{ 'path': 'std::collections::vec_deque::VecDeque', 'name': 'from_iter' },
23-
{ 'path': 'std::collections::vec_deque::VecDeque', 'name': 'into_iter' },
20+
{ 'path': 'std::collections::VecDeque', 'name': 'iter' },
21+
{ 'path': 'std::collections::VecDeque', 'name': 'iter_mut' },
22+
{ 'path': 'std::collections::VecDeque', 'name': 'from_iter' },
23+
{ 'path': 'std::collections::VecDeque', 'name': 'into_iter' },
2424
],
2525
},
2626
{

tests/rustdoc-js-std/path-ordering.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ const EXPECTED = [
33
query: 'hashset::insert',
44
others: [
55
// ensure hashset::insert comes first
6-
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'insert' },
7-
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert' },
8-
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_with' },
6+
{ 'path': 'std::collections::HashSet', 'name': 'insert' },
7+
{ 'path': 'std::collections::HashSet', 'name': 'get_or_insert' },
8+
{ 'path': 'std::collections::HashSet', 'name': 'get_or_insert_with' },
99
],
1010
},
1111
{
1212
query: 'hash::insert',
1313
others: [
1414
// ensure hashset/hashmap::insert come first
15-
{ 'path': 'std::collections::hash_map::HashMap', 'name': 'insert' },
16-
{ 'path': 'std::collections::hash_set::HashSet', 'name': 'insert' },
15+
{ 'path': 'std::collections::HashMap', 'name': 'insert' },
16+
{ 'path': 'std::collections::HashSet', 'name': 'insert' },
1717
],
1818
},
1919
];

tests/rustdoc-js-std/simd-type-signatures.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,59 @@ const EXPECTED = [
1111
'query': 'simd<i16>, simd<i16> -> simd<i16>',
1212
'others': [
1313
{
14-
'path': 'std::simd::prelude::Simd',
14+
'path': 'std::simd::Simd',
1515
'name': 'simd_max',
16-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_max'
16+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_max'
1717
},
1818
{
19-
'path': 'std::simd::prelude::Simd',
19+
'path': 'std::simd::Simd',
2020
'name': 'simd_min',
21-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_min'
21+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_min'
2222
},
2323
{
24-
'path': 'std::simd::prelude::Simd',
24+
'path': 'std::simd::Simd',
2525
'name': 'saturating_add',
26-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_add'
26+
'href': '../std/simd/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_add'
2727
},
2828
{
29-
'path': 'std::simd::prelude::Simd',
29+
'path': 'std::simd::Simd',
3030
'name': 'saturating_sub',
31-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_sub'
31+
'href': '../std/simd/struct.Simd.html#impl-SimdInt-for-Simd%3Ci16,+N%3E/method.saturating_sub'
3232
},
3333
{
34-
'path': 'std::simd::prelude::Simd',
34+
'path': 'std::simd::Simd',
3535
'name': 'simd_clamp',
36-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
36+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci16,+N%3E/method.simd_clamp'
3737
},
3838
],
3939
},
4040
{
4141
'query': 'simd<i8>, simd<i8> -> simd<i8>',
4242
'others': [
4343
{
44-
'path': 'std::simd::prelude::Simd',
44+
'path': 'std::simd::Simd',
4545
'name': 'simd_max',
46-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_max'
46+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_max'
4747
},
4848
{
49-
'path': 'std::simd::prelude::Simd',
49+
'path': 'std::simd::Simd',
5050
'name': 'simd_min',
51-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_min'
51+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_min'
5252
},
5353
{
54-
'path': 'std::simd::prelude::Simd',
54+
'path': 'std::simd::Simd',
5555
'name': 'saturating_add',
56-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_add'
56+
'href': '../std/simd/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_add'
5757
},
5858
{
59-
'path': 'std::simd::prelude::Simd',
59+
'path': 'std::simd::Simd',
6060
'name': 'saturating_sub',
61-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_sub'
61+
'href': '../std/simd/struct.Simd.html#impl-SimdInt-for-Simd%3Ci8,+N%3E/method.saturating_sub'
6262
},
6363
{
64-
'path': 'std::simd::prelude::Simd',
64+
'path': 'std::simd::Simd',
6565
'name': 'simd_clamp',
66-
'href': '../std/simd/prelude/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
66+
'href': '../std/simd/struct.Simd.html#impl-SimdOrd-for-Simd%3Ci8,+N%3E/method.simd_clamp'
6767
},
6868
],
6969
},
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;

tests/rustdoc/intra-doc/pub-use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern crate inner;
77
/// [mod@std::env] [g]
88
//@ has outer/index.html
99
//@ has - '//a[@href="{{channel}}/std/env/index.html"]' "std::env"
10-
//@ has - '//a[@href="fn.f.html"]' "g"
10+
//@ has - '//a[@href="fn.g.html"]' "g"
1111
pub use f as g;
1212

1313
// Make sure the documentation is actually correct by documenting an inlined re-export

0 commit comments

Comments
 (0)