Skip to content

Commit ec9be91

Browse files
committed
Auto merge of #47050 - ollie27:rustdoc_import_links, r=QuietMisdreavus
rustdoc: Don't try to generate links for modules in import paths The modules may be private or may even be enums so it would generate dead links. Fixes #29814 Fixes #46766 Fixes #46767
2 parents b84385b + 95f9491 commit ec9be91

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

src/librustdoc/html/format.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -435,32 +435,10 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
435435
fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
436436
print_all: bool, use_absolute: bool) -> fmt::Result {
437437
let last = path.segments.last().unwrap();
438-
let rel_root = match &*path.segments[0].name {
439-
"self" => Some("./".to_string()),
440-
_ => None,
441-
};
442438

443439
if print_all {
444-
let amt = path.segments.len() - 1;
445-
match rel_root {
446-
Some(mut root) => {
447-
for seg in &path.segments[..amt] {
448-
if "super" == seg.name || "self" == seg.name || w.alternate() {
449-
write!(w, "{}::", seg.name)?;
450-
} else {
451-
root.push_str(&seg.name);
452-
root.push_str("/");
453-
write!(w, "<a class=\"mod\" href=\"{}index.html\">{}</a>::",
454-
root,
455-
seg.name)?;
456-
}
457-
}
458-
}
459-
None => {
460-
for seg in &path.segments[..amt] {
461-
write!(w, "{}::", seg.name)?;
462-
}
463-
}
440+
for seg in &path.segments[..path.segments.len() - 1] {
441+
write!(w, "{}::", seg.name)?;
464442
}
465443
}
466444
if w.alternate() {

src/test/rustdoc/issue-46766.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
pub enum Enum{Variant}
14+
pub use self::Enum::Variant;
15+
16+
// @!has foo/index.html '//a/@href' './Enum/index.html'

src/test/rustdoc/issue-46767.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
mod private {
14+
pub enum Enum{Variant}
15+
}
16+
pub use self::private::Enum::*;
17+
18+
// @!has foo/index.html '//a/@href' './private/index.html'

0 commit comments

Comments
 (0)