diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index dec74e60c71f3..aeb15821b0bb7 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -16,6 +16,7 @@ fn main() { let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set"); let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set"); let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"); + let mut has_unstable = false; use std::str::FromStr; @@ -54,9 +55,22 @@ fn main() { // it up so we can make rustdoc print this into the docs if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") { // This "unstable-options" can be removed when `--crate-version` is stabilized - cmd.arg("-Z") - .arg("unstable-options") - .arg("--crate-version").arg(version); + if !has_unstable { + cmd.arg("-Z") + .arg("unstable-options"); + } + cmd.arg("--crate-version").arg(version); + has_unstable = true; + } + + // Needed to be able to run all rustdoc tests. + if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") { + // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized + if !has_unstable { + cmd.arg("-Z") + .arg("unstable-options"); + } + cmd.arg("--generate-redirect-pages"); } if verbose > 1 { diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d14b23e5988cb..660f9b9ef578a 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -517,6 +517,7 @@ impl Step for Std { cargo.arg("--") .arg("--markdown-css").arg("rust.css") .arg("--markdown-no-toc") + .arg("--generate-redirect-pages") .arg("--index-page").arg(&builder.src.join("src/doc/index.md")); builder.run(&mut cargo); @@ -581,7 +582,9 @@ impl Step for Test { let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc"); compile::test_cargo(builder, &compiler, target, &mut cargo); - cargo.arg("--no-deps").arg("-p").arg("test"); + cargo.arg("--no-deps") + .arg("-p").arg("test") + .env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1"); builder.run(&mut cargo); builder.cp_r(&my_out, &out); @@ -650,9 +653,9 @@ impl Step for WhitelistedRustc { // We don't want to build docs for internal compiler dependencies in this // step (there is another step for that). Therefore, we whitelist the crates // for which docs must be built. - cargo.arg("--no-deps"); for krate in &["proc_macro"] { - cargo.arg("-p").arg(krate); + cargo.arg("-p").arg(krate) + .env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1"); } builder.run(&mut cargo); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ec4ee2d66a599..91fbe877cb7d9 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -192,6 +192,8 @@ pub struct RenderOptions { /// If false, the `select` element to have search filtering by crates on rendered docs /// won't be generated. pub generate_search_filter: bool, + /// Option (disabled by default) to generate files used by RLS and some other tools. + pub generate_redirect_pages: bool, } impl Options { @@ -436,6 +438,7 @@ impl Options { let static_root_path = matches.opt_str("static-root-path"); let generate_search_filter = !matches.opt_present("disable-per-crate-search"); let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from); + let generate_redirect_pages = matches.opt_present("generate-redirect-pages"); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -480,6 +483,7 @@ impl Options { markdown_css, markdown_playground_url, generate_search_filter, + generate_redirect_pages, } }) } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e660d27d74b4c..692d879668877 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -148,6 +148,8 @@ struct SharedContext { /// If false, the `select` element to have search filtering by crates on rendered docs /// won't be generated. pub generate_search_filter: bool, + /// Option disabled by default to generate files used by RLS and some other tools. + pub generate_redirect_pages: bool, } impl SharedContext { @@ -516,6 +518,7 @@ pub fn run(mut krate: clean::Crate, resource_suffix, static_root_path, generate_search_filter, + generate_redirect_pages, .. } = options; @@ -545,6 +548,7 @@ pub fn run(mut krate: clean::Crate, resource_suffix, static_root_path, generate_search_filter, + generate_redirect_pages, }; // If user passed in `--playground-url` arg, we fill in crate name here @@ -2246,17 +2250,18 @@ impl Context { if !self.render_redirect_pages { all.append(full_path(self, &item), &item_type); } - // Redirect from a sane URL using the namespace to Rustdoc's - // URL for the page. - let redir_name = format!("{}.{}.html", name, item_type.name_space()); - let redir_dst = self.dst.join(redir_name); - if let Ok(redirect_out) = OpenOptions::new().create_new(true) - .write(true) - .open(&redir_dst) { - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + if self.shared.generate_redirect_pages { + // Redirect from a sane URL using the namespace to Rustdoc's + // URL for the page. + let redir_name = format!("{}.{}.html", name, item_type.name_space()); + let redir_dst = self.dst.join(redir_name); + if let Ok(redirect_out) = OpenOptions::new().create_new(true) + .write(true) + .open(&redir_dst) { + let mut redirect_out = BufWriter::new(redirect_out); + try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + } } - // If the item is a macro, redirect from the old macro URL (with !) // to the new one (without). if item_type == ItemType::Macro { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 0b34a27794f0f..43b366535159c 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -345,6 +345,11 @@ fn opts() -> Vec { "Directory to persist doctest executables into", "PATH") }), + unstable("generate-redirect-pages", |o| { + o.optflag("", + "generate-redirect-pages", + "Generate extra pages to support legacy URLs and tool links") + }), ] } diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index a7c25538f7c44..c6bac51c5740d 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,3 +1,5 @@ +// compile-flags:-Z unstable-options --generate-redirect-pages + use std::ops::Deref; pub struct Foo; diff --git a/src/test/rustdoc/issue-21092.rs b/src/test/rustdoc/issue-21092.rs index 14f547abd9a68..b054145a4831a 100644 --- a/src/test/rustdoc/issue-21092.rs +++ b/src/test/rustdoc/issue-21092.rs @@ -3,7 +3,6 @@ extern crate issue_21092; -// @has issue_21092/Bar.t.html // @has issue_21092/struct.Bar.html // @has - '//*[@id="associatedtype.Bar"]' 'type Bar = i32' pub use issue_21092::{Foo, Bar}; diff --git a/src/test/rustdoc/issue-35169-2.rs b/src/test/rustdoc/issue-35169-2.rs index 0caead100d666..33f7646ced68b 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -23,7 +23,6 @@ impl DerefMut for Bar { fn deref_mut(&mut self) -> &mut Foo { loop {} } } -// @has issue_35169_2/Bar.t.html // @has issue_35169_2/struct.Bar.html // @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 0978b103076fe..04fffc40572a6 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -18,7 +18,6 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } -// @has issue_35169/Bar.t.html // @has issue_35169/struct.Bar.html // @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' diff --git a/src/test/rustdoc/macros.rs b/src/test/rustdoc/macros.rs index c66a2c845bfd8..fb4f02ad16052 100644 --- a/src/test/rustdoc/macros.rs +++ b/src/test/rustdoc/macros.rs @@ -2,8 +2,6 @@ // @has - //pre '() => { ... };' // @has - //pre '($a:tt) => { ... };' // @has - //pre '($e:expr) => { ... };' -// @has macros/macro.my_macro!.html -// @has - //a 'macro.my_macro.html' #[macro_export] macro_rules! my_macro { () => []; diff --git a/src/test/rustdoc/src-links.rs b/src/test/rustdoc/src-links.rs index 902a319a7b906..353ce10243e00 100644 --- a/src/test/rustdoc/src-links.rs +++ b/src/test/rustdoc/src-links.rs @@ -14,13 +14,11 @@ pub mod bar { // @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html' pub mod baz { /// Dox - // @has foo/bar/baz/baz.v.html // @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html' pub fn baz() { } } /// Dox - // @has foo/bar/Foobar.t.html // @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html' pub trait Foobar { fn dummy(&self) { } } diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index 35cea8afe2146..235f0e852da2c 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,3 +1,5 @@ +// compile-flags:-Z unstable-options --generate-redirect-pages + // @has structfields/Foo.t.html // @has - struct.Foo.html // @has structfields/struct.Foo.html diff --git a/src/test/rustdoc/without-redirect.rs b/src/test/rustdoc/without-redirect.rs new file mode 100644 index 0000000000000..a076f8a3c5ec7 --- /dev/null +++ b/src/test/rustdoc/without-redirect.rs @@ -0,0 +1,13 @@ +#![crate_name = "foo"] + +// @has foo/macro.bar.html +// @has foo/macro.bar!.html +// @!has foo/bar.m.html +#[macro_export] +macro_rules! bar { + () => {} +} + +// @has foo/struct.Bar.html +// @!has foo/Bar.t.html +pub struct Bar;