Auto merge of #34245 - ollie27:rustdoc_redirect_rename, r=alexcrichton
rustdoc: Fix redirect pages for renamed reexports We need to use the name of the target not the name of the current item when creating the link. An example in `std` is [`std::sys::ext`](https://doc.rust-lang.org/nightly/std/sys/ext/index.html).
This commit is contained in:
commit
1a942f60f0
@ -1343,12 +1343,12 @@ impl Context {
|
|||||||
} else {
|
} else {
|
||||||
let mut url = repeat("../").take(cx.current.len())
|
let mut url = repeat("../").take(cx.current.len())
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
if let Some(&(ref names, _)) = cache().paths.get(&it.def_id) {
|
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
||||||
for name in &names[..names.len() - 1] {
|
for name in &names[..names.len() - 1] {
|
||||||
url.push_str(name);
|
url.push_str(name);
|
||||||
url.push_str("/");
|
url.push_str("/");
|
||||||
}
|
}
|
||||||
url.push_str(&item_path(it));
|
url.push_str(&item_path(ty, names.last().unwrap()));
|
||||||
layout::redirect(writer, &url)?;
|
layout::redirect(writer, &url)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1409,7 +1409,8 @@ impl Context {
|
|||||||
render(&mut buf, self, &item, true).unwrap();
|
render(&mut buf, self, &item, true).unwrap();
|
||||||
// buf will be empty if the item is stripped and there is no redirect for it
|
// buf will be empty if the item is stripped and there is no redirect for it
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
let joint_dst = self.dst.join(&item_path(&item));
|
let joint_dst = self.dst.join(&item_path(shortty(&item),
|
||||||
|
item.name.as_ref().unwrap()));
|
||||||
try_err!(fs::create_dir_all(&self.dst), &self.dst);
|
try_err!(fs::create_dir_all(&self.dst), &self.dst);
|
||||||
let mut dst = try_err!(File::create(&joint_dst), &joint_dst);
|
let mut dst = try_err!(File::create(&joint_dst), &joint_dst);
|
||||||
try_err!(dst.write_all(&buf), &joint_dst);
|
try_err!(dst.write_all(&buf), &joint_dst);
|
||||||
@ -1531,7 +1532,7 @@ impl<'a> Item<'a> {
|
|||||||
Some(format!("{root}{path}/{file}?gotosrc={goto}",
|
Some(format!("{root}{path}/{file}?gotosrc={goto}",
|
||||||
root = root,
|
root = root,
|
||||||
path = path[..path.len() - 1].join("/"),
|
path = path[..path.len() - 1].join("/"),
|
||||||
file = item_path(self.item),
|
file = item_path(shortty(self.item), self.item.name.as_ref().unwrap()),
|
||||||
goto = self.item.def_id.index.as_usize()))
|
goto = self.item.def_id.index.as_usize()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1623,13 +1624,10 @@ impl<'a> fmt::Display for Item<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_path(item: &clean::Item) -> String {
|
fn item_path(ty: ItemType, name: &str) -> String {
|
||||||
if item.is_mod() {
|
match ty {
|
||||||
format!("{}/index.html", item.name.as_ref().unwrap())
|
ItemType::Module => format!("{}/index.html", name),
|
||||||
} else {
|
_ => format!("{}.{}.html", ty.to_static_str(), name),
|
||||||
format!("{}.{}.html",
|
|
||||||
shortty(item).to_static_str(),
|
|
||||||
*item.name.as_ref().unwrap())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1821,7 +1819,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||||||
docs = shorter(Some(&Markdown(doc_value).to_string())),
|
docs = shorter(Some(&Markdown(doc_value).to_string())),
|
||||||
class = shortty(myitem),
|
class = shortty(myitem),
|
||||||
stab = myitem.stability_class(),
|
stab = myitem.stability_class(),
|
||||||
href = item_path(myitem),
|
href = item_path(shortty(myitem), myitem.name.as_ref().unwrap()),
|
||||||
title = full_path(cx, myitem))?;
|
title = full_path(cx, myitem))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
src/test/rustdoc/redirect-rename.rs
Normal file
32
src/test/rustdoc/redirect-rename.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
mod hidden {
|
||||||
|
// @has foo/hidden/struct.Foo.html
|
||||||
|
// @has - '//p/a' '../../foo/struct.FooBar.html'
|
||||||
|
pub struct Foo {}
|
||||||
|
|
||||||
|
// @has foo/hidden/bar/index.html
|
||||||
|
// @has - '//p/a' '../../foo/baz/index.html'
|
||||||
|
pub mod bar {
|
||||||
|
// @has foo/hidden/bar/struct.Thing.html
|
||||||
|
// @has - '//p/a' '../../foo/baz/struct.Thing.html'
|
||||||
|
pub struct Thing {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @has foo/struct.FooBar.html
|
||||||
|
pub use hidden::Foo as FooBar;
|
||||||
|
|
||||||
|
// @has foo/baz/index.html
|
||||||
|
// @has foo/baz/struct.Thing.html
|
||||||
|
pub use hidden::bar as baz;
|
Loading…
Reference in New Issue
Block a user