Skip to content

Commit

Permalink
Rollup merge of rust-lang#76082 - jyn514:top-level-links, r=ollie27,G…
Browse files Browse the repository at this point in the history
…uillaumeGomez

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
  • Loading branch information
Dylan-DPC authored Sep 4, 2020
2 parents 07a6c2c + d715015 commit aa6f881
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/rustdoc/auxiliary/intra-link-pub-use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_name = "inner"]

/// Documentation, including a link to [std::ptr]
pub fn f() {}
27 changes: 27 additions & 0 deletions src/test/rustdoc/intra-link-pub-use.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit aa6f881

Please sign in to comment.