diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-09-05 16:28:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-05 16:28:28 +0200 |
| commit | f1eb5f800fddbea8876930cdeffa55545e17f447 (patch) | |
| tree | 47726eb4a325f5d3df97630a4209a91d2327e523 | |
| parent | ed39e6d60a415f827aaca7fdbd571b309b1bb310 (diff) | |
| parent | d7150154fa5c35c0b570570f156ba3a5cc6dfb1d (diff) | |
| download | rust-f1eb5f800fddbea8876930cdeffa55545e17f447.tar.gz rust-f1eb5f800fddbea8876930cdeffa55545e17f447.zip | |
Rollup merge of #76082 - jyn514:top-level-links, r=ollie27,GuillaumeGomez
Fix intra-doc links on pub re-exports Partial fix for https://github.com/rust-lang/rust/issues/76073 - This removes the incorrect error, but doesn't show the documentation anywhere. r? @GuillaumeGomez
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 9 | ||||
| -rw-r--r-- | src/test/rustdoc/auxiliary/intra-link-pub-use.rs | 4 | ||||
| -rw-r--r-- | src/test/rustdoc/intra-link-pub-use.rs | 27 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 13bfca4c5cd..5d10e2e149b 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -582,6 +582,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { let parent_node = if item.is_fake() { // FIXME: is this correct? None + // If we're documenting the crate root itself, it has no parent. Use the root instead. + } else if item.def_id.is_top_level_module() { + Some(item.def_id) } else { let mut current = item.def_id; // The immediate parent might not always be a module. @@ -593,6 +596,12 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { } current = parent; } else { + debug!( + "{:?} has no parent (kind={:?}, original was {:?})", + current, + self.cx.tcx.def_kind(current), + item.def_id + ); break None; } } diff --git a/src/test/rustdoc/auxiliary/intra-link-pub-use.rs b/src/test/rustdoc/auxiliary/intra-link-pub-use.rs new file mode 100644 index 00000000000..a4db2ffc445 --- /dev/null +++ b/src/test/rustdoc/auxiliary/intra-link-pub-use.rs @@ -0,0 +1,4 @@ +#![crate_name = "inner"] + +/// Documentation, including a link to [std::ptr] +pub fn f() {} diff --git a/src/test/rustdoc/intra-link-pub-use.rs b/src/test/rustdoc/intra-link-pub-use.rs new file mode 100644 index 00000000000..dd52249abc6 --- /dev/null +++ b/src/test/rustdoc/intra-link-pub-use.rs @@ -0,0 +1,27 @@ +// aux-build: intra-link-pub-use.rs +#![deny(broken_intra_doc_links)] +#![crate_name = "outer"] + +extern crate inner; + +/// [mod@std::env] [g] + +// FIXME: This can't be tested because rustdoc doesn't show documentation on pub re-exports. +// Until then, comment out the `htmldocck` test. +// This test still does something; namely check that no incorrect errors are emitted when +// documenting the re-export. + +// @has outer/index.html +// @ has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/fn.var.html"]' "std::env" +// @ has - '//a[@href="../outer/fn.f.html"]' "g" +pub use f as g; + +// FIXME: same as above +/// [std::env] +extern crate self as _; + +// Make sure the documentation is actually correct by documenting an inlined re-export +/// [mod@std::env] +// @has outer/fn.f.html +// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/index.html"]' "std::env" +pub use inner::f; |
