From 1ac727772bd91b6e35b624e3252e6a6bd681c70b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Dec 2018 22:47:09 +0100 Subject: [PATCH 1/5] Remove rustdoc old style files generation --- src/librustdoc/html/render.rs | 22 +--------------------- src/test/rustdoc/issue-19190.rs | 3 --- src/test/rustdoc/issue-21092.rs | 1 - src/test/rustdoc/issue-35169-2.rs | 8 -------- src/test/rustdoc/issue-35169.rs | 8 -------- src/test/rustdoc/macros.rs | 2 -- src/test/rustdoc/old-style-files.rs | 23 +++++++++++++++++++++++ src/test/rustdoc/src-links.rs | 2 -- src/test/rustdoc/structfields.rs | 5 ----- 9 files changed, 24 insertions(+), 50 deletions(-) create mode 100644 src/test/rustdoc/old-style-files.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 86fb51419c2..4f237dc85a5 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -33,7 +33,7 @@ use std::error; use std::fmt::{self, Display, Formatter, Write as FmtWrite}; use std::ffi::OsStr; -use std::fs::{self, File, OpenOptions}; +use std::fs::{self, File}; use std::io::prelude::*; use std::io::{self, BufWriter, BufReader}; use std::mem; @@ -2229,26 +2229,6 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result 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 the item is a macro, redirect from the old macro URL (with !) - // to the new one (without). - if item_type == ItemType::Macro { - let redir_name = format!("{}.{}!.html", item_type, name); - let redir_dst = self.dst.join(redir_name); - let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); - } } } Ok(()) diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index a7c25538f7c..4d3b7622970 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -13,9 +13,6 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } -// @has issue_19190/Bar.t.html // @has issue_19190/struct.Bar.html -// @has - '//*[@id="foo.v"]' 'fn foo(&self)' // @has - '//*[@id="method.foo"]' 'fn foo(&self)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-21092.rs b/src/test/rustdoc/issue-21092.rs index 14f547abd9a..b054145a483 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 0caead100d6..7dea268ec02 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -23,19 +23,11 @@ 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)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 0978b103076..883d5d0158d 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -18,19 +18,11 @@ 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)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @!has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/macros.rs b/src/test/rustdoc/macros.rs index c66a2c845bf..fb4f02ad160 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/old-style-files.rs b/src/test/rustdoc/old-style-files.rs new file mode 100644 index 00000000000..fb6697e18fb --- /dev/null +++ b/src/test/rustdoc/old-style-files.rs @@ -0,0 +1,23 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![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; diff --git a/src/test/rustdoc/src-links.rs b/src/test/rustdoc/src-links.rs index 902a319a7b9..353ce10243e 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 35cea8afe21..cd8957aa2ec 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,6 +1,5 @@ // @has structfields/Foo.t.html // @has - struct.Foo.html -// @has structfields/struct.Foo.html pub struct Foo { // @has - //pre "pub a: ()" pub a: (), @@ -14,8 +13,6 @@ pub struct Foo { pub d: usize, } -// @has structfields/Bar.t.html -// @has - struct.Bar.html // @has structfields/struct.Bar.html pub struct Bar { // @has - //pre "pub a: ()" @@ -23,8 +20,6 @@ pub struct Bar { // @!has - //pre "// some fields omitted" } -// @has structfields/Qux.t.html -// @has - enum.Qux.html // @has structfields/enum.Qux.html pub enum Qux { Quz { From 270151bffb0be259ff20feee3801bb124c2c39ec Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Dec 2018 00:33:00 +0100 Subject: [PATCH 2/5] Add generate-old-style-files option to rustdoc --- src/bootstrap/doc.rs | 4 +++- src/librustdoc/config.rs | 4 ++++ src/librustdoc/html/render.rs | 27 ++++++++++++++++++++++++++- src/librustdoc/lib.rs | 5 +++++ src/test/rustdoc/issue-19190.rs | 5 +++++ src/test/rustdoc/issue-35169-2.rs | 7 +++++++ src/test/rustdoc/issue-35169.rs | 7 +++++++ src/test/rustdoc/old-style-files.rs | 23 ----------------------- src/test/rustdoc/structfields.rs | 7 +++++++ src/test/rustdoc/without-redirect.rs | 13 +++++++++++++ 10 files changed, 77 insertions(+), 25 deletions(-) delete mode 100644 src/test/rustdoc/old-style-files.rs create mode 100644 src/test/rustdoc/without-redirect.rs diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index eec193c21f5..0028997a7df 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -317,7 +317,8 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned Result { 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 @@ pub fn from_matches(matches: &getopts::Matches) -> Result { 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 4f237dc85a5..179ae56d9b6 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -33,7 +33,7 @@ use std::error; use std::fmt::{self, Display, Formatter, Write as FmtWrite}; use std::ffi::OsStr; -use std::fs::{self, File}; +use std::fs::{self, File, OpenOptions}; use std::io::prelude::*; use std::io::{self, BufWriter, BufReader}; use std::mem; @@ -136,6 +136,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 { @@ -504,6 +506,7 @@ pub fn run(mut krate: clean::Crate, resource_suffix, static_root_path, generate_search_filter, + generate_redirect_pages, .. } = options; @@ -533,6 +536,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 @@ -2229,6 +2233,27 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result if !self.render_redirect_pages { all.append(full_path(self, &item), &item_type); } + 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 { + let redir_name = format!("{}.{}!.html", item_type, name); + let redir_dst = self.dst.join(redir_name); + let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); + let mut redirect_out = BufWriter::new(redirect_out); + try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + } + } } } Ok(()) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index f4149b5f357..290f9586404 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -348,6 +348,11 @@ fn opts() -> Vec { "Directory to persist doctest executables into", "PATH") }), + stable("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 4d3b7622970..e023e79fcde 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,3 +1,5 @@ +// compile-flags:--generate-redirect-pages + use std::ops::Deref; pub struct Foo; @@ -13,6 +15,9 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } +// @has issue_19190/Bar.t.html // @has issue_19190/struct.Bar.html +// @has - '//*[@id="foo.v"]' 'fn foo(&self)' // @has - '//*[@id="method.foo"]' 'fn foo(&self)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169-2.rs b/src/test/rustdoc/issue-35169-2.rs index 7dea268ec02..33f7646ced6 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -24,10 +24,17 @@ fn deref_mut(&mut self) -> &mut Foo { loop {} } } // @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)' +// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' +// @has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' +// @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 883d5d0158d..04fffc40572 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -19,10 +19,17 @@ fn deref(&self) -> &Foo { loop {} } } // @has issue_35169/struct.Bar.html +// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' +// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' +// @!has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' +// @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/old-style-files.rs b/src/test/rustdoc/old-style-files.rs deleted file mode 100644 index fb6697e18fb..00000000000 --- a/src/test/rustdoc/old-style-files.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![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; diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index cd8957aa2ec..bfe116acffc 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,5 +1,8 @@ +// compile-flags:--generate-redirect-pages + // @has structfields/Foo.t.html // @has - struct.Foo.html +// @has structfields/struct.Foo.html pub struct Foo { // @has - //pre "pub a: ()" pub a: (), @@ -13,6 +16,8 @@ pub struct Foo { pub d: usize, } +// @has structfields/Bar.t.html +// @has - struct.Bar.html // @has structfields/struct.Bar.html pub struct Bar { // @has - //pre "pub a: ()" @@ -20,6 +25,8 @@ pub struct Bar { // @!has - //pre "// some fields omitted" } +// @has structfields/Qux.t.html +// @has - enum.Qux.html // @has structfields/enum.Qux.html pub enum Qux { Quz { diff --git a/src/test/rustdoc/without-redirect.rs b/src/test/rustdoc/without-redirect.rs new file mode 100644 index 00000000000..d473dd8f428 --- /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; From 65440a3f4fe42acbe9970638b567ee3fa68d4824 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 27 Jan 2019 00:44:33 +0100 Subject: [PATCH 3/5] Make 'generate-redirect-pages' option unstable --- src/librustdoc/lib.rs | 2 +- src/test/rustdoc/issue-19190.rs | 2 +- src/test/rustdoc/structfields.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 290f9586404..4e0302b0224 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -348,7 +348,7 @@ fn opts() -> Vec { "Directory to persist doctest executables into", "PATH") }), - stable("generate-redirect-pages", |o| { + 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 e023e79fcde..c6bac51c574 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,4 +1,4 @@ -// compile-flags:--generate-redirect-pages +// compile-flags:-Z unstable-options --generate-redirect-pages use std::ops::Deref; diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index bfe116acffc..235f0e852da 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,4 +1,4 @@ -// compile-flags:--generate-redirect-pages +// compile-flags:-Z unstable-options --generate-redirect-pages // @has structfields/Foo.t.html // @has - struct.Foo.html From 397eb4f237b92f77eadf12c0bea7cfea5a31a92a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 Jan 2019 11:39:19 +0100 Subject: [PATCH 4/5] Add missing generation for test and proc_macro, remove old macro redirection --- src/bootstrap/bin/rustdoc.rs | 20 +++++++++++++++++--- src/bootstrap/doc.rs | 11 ++++++----- src/librustdoc/html/render.rs | 9 --------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index dec74e60c71..aeb15821b0b 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 0028997a7df..af95b622e23 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -317,8 +317,7 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result 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 { - let redir_name = format!("{}.{}!.html", item_type, name); - let redir_dst = self.dst.join(redir_name); - let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); - } } } } From d26475505b4c2bfc6299d3c6c38b1963c3bd86e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 9 Feb 2019 01:07:38 +0100 Subject: [PATCH 5/5] put back macro redirect --- src/librustdoc/html/render.rs | 9 +++++++++ src/test/rustdoc/without-redirect.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ecc5bcff12d..105bf611282 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2245,6 +2245,15 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result 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 { + let redir_name = format!("{}.{}!.html", item_type, name); + let redir_dst = self.dst.join(redir_name); + let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); + let mut redirect_out = BufWriter::new(redirect_out); + try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + } } } Ok(()) diff --git a/src/test/rustdoc/without-redirect.rs b/src/test/rustdoc/without-redirect.rs index d473dd8f428..a076f8a3c5e 100644 --- a/src/test/rustdoc/without-redirect.rs +++ b/src/test/rustdoc/without-redirect.rs @@ -1,7 +1,7 @@ #![crate_name = "foo"] // @has foo/macro.bar.html -// @!has foo/macro.bar!.html +// @has foo/macro.bar!.html // @!has foo/bar.m.html #[macro_export] macro_rules! bar {