Skip to content

Commit 956216e

Browse files
authored
Rollup merge of rust-lang#76082 - jyn514:top-level-links, r=ollie27,GuillaumeGomez
Fix intra-doc links on pub re-exports Partial fix for rust-lang#76073 - This removes the incorrect error, but doesn't show the documentation anywhere. r? @GuillaumeGomez
2 parents baded64 + d715015 commit 956216e

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+9
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
582582
let parent_node = if item.is_fake() {
583583
// FIXME: is this correct?
584584
None
585+
// If we're documenting the crate root itself, it has no parent. Use the root instead.
586+
} else if item.def_id.is_top_level_module() {
587+
Some(item.def_id)
585588
} else {
586589
let mut current = item.def_id;
587590
// The immediate parent might not always be a module.
@@ -593,6 +596,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
593596
}
594597
current = parent;
595598
} else {
599+
debug!(
600+
"{:?} has no parent (kind={:?}, original was {:?})",
601+
current,
602+
self.cx.tcx.def_kind(current),
603+
item.def_id
604+
);
596605
break None;
597606
}
598607
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![crate_name = "inner"]
2+
3+
/// Documentation, including a link to [std::ptr]
4+
pub fn f() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// aux-build: intra-link-pub-use.rs
2+
#![deny(broken_intra_doc_links)]
3+
#![crate_name = "outer"]
4+
5+
extern crate inner;
6+
7+
/// [mod@std::env] [g]
8+
9+
// FIXME: This can't be tested because rustdoc doesn't show documentation on pub re-exports.
10+
// Until then, comment out the `htmldocck` test.
11+
// This test still does something; namely check that no incorrect errors are emitted when
12+
// documenting the re-export.
13+
14+
// @has outer/index.html
15+
// @ has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/fn.var.html"]' "std::env"
16+
// @ has - '//a[@href="../outer/fn.f.html"]' "g"
17+
pub use f as g;
18+
19+
// FIXME: same as above
20+
/// [std::env]
21+
extern crate self as _;
22+
23+
// Make sure the documentation is actually correct by documenting an inlined re-export
24+
/// [mod@std::env]
25+
// @has outer/fn.f.html
26+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/index.html"]' "std::env"
27+
pub use inner::f;

0 commit comments

Comments
 (0)