Skip to content

Commit 0dc4c94

Browse files
committed
Add docs.rs/rustc redirect.
`rustc` is a reserved crate name and will not appear on crates.io, so we can use it for this instead.
1 parent 9f1acc1 commit 0dc4c94

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/web/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,11 @@ mod test {
723723
// with or without slash
724724
assert_redirect("/proc-macro", target, web)?;
725725
assert_redirect("/proc-macro/", target, web)?;
726+
727+
let target = "https://doc.rust-lang.org/nightly/nightly-rustc/";
728+
// with or without slash
729+
assert_redirect("/rustc", target, web)?;
730+
assert_redirect("/rustc/", target, web)?;
726731
Ok(())
727732
})
728733
}

src/web/routes.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,18 @@ pub(super) fn build_routes() -> Routes {
157157
for redirect in DOC_RUST_LANG_ORG_REDIRECTS {
158158
routes.internal_page(
159159
&format!("/{}", redirect),
160-
super::rustdoc::RustLangRedirector::new(redirect),
160+
super::rustdoc::RustLangRedirector::new("stable", redirect),
161161
);
162162
}
163163
// redirect proc-macro to proc_macro
164164
routes.internal_page(
165165
"/proc-macro",
166-
super::rustdoc::RustLangRedirector::new("proc_macro"),
166+
super::rustdoc::RustLangRedirector::new("stable", "proc_macro"),
167+
);
168+
// redirect rustc to nightly rustc docs
169+
routes.internal_page(
170+
"/rustc",
171+
super::rustdoc::RustLangRedirector::new("nightly", "nightly-rustc"),
167172
);
168173

169174
routes

src/web/rustdoc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ pub struct RustLangRedirector {
2727
}
2828

2929
impl RustLangRedirector {
30-
pub fn new(target: &'static str) -> Self {
31-
let url = iron::url::Url::parse("https://doc.rust-lang.org/stable/")
30+
pub fn new(version: &str, target: &str) -> Self {
31+
let url = iron::url::Url::parse("https://doc.rust-lang.org/")
3232
.expect("failed to parse rust-lang.org base URL")
33+
.join(version)
34+
.expect("failed to append Rust version to rust-lang.org base URL")
3335
.join(target)
3436
.expect("failed to append crate name to rust-lang.org base URL");
3537
let url = Url::from_generic_url(url).expect("failed to convert url::Url to iron::Url");

0 commit comments

Comments
 (0)