Skip to content

Commit f8ccdeb

Browse files
committed
Rollup merge of rust-lang#57929 - GuillaumeGomez:rustodc-remove-old-style-files, r=ollie27
Rustdoc remove old style files Reopening of rust-lang#56577 (which I can't seem to reopen...). I made the flag unstable so with this change, what was blocking the PR is now gone I assume.
2 parents 4739cd8 + d264755 commit f8ccdeb

13 files changed

+64
-23
lines changed

src/bootstrap/bin/rustdoc.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn main() {
1616
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
1717
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
1818
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
19+
let mut has_unstable = false;
1920

2021
use std::str::FromStr;
2122

@@ -54,9 +55,22 @@ fn main() {
5455
// it up so we can make rustdoc print this into the docs
5556
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
5657
// This "unstable-options" can be removed when `--crate-version` is stabilized
57-
cmd.arg("-Z")
58-
.arg("unstable-options")
59-
.arg("--crate-version").arg(version);
58+
if !has_unstable {
59+
cmd.arg("-Z")
60+
.arg("unstable-options");
61+
}
62+
cmd.arg("--crate-version").arg(version);
63+
has_unstable = true;
64+
}
65+
66+
// Needed to be able to run all rustdoc tests.
67+
if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") {
68+
// This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
69+
if !has_unstable {
70+
cmd.arg("-Z")
71+
.arg("unstable-options");
72+
}
73+
cmd.arg("--generate-redirect-pages");
6074
}
6175

6276
if verbose > 1 {

src/bootstrap/doc.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ impl Step for Std {
517517
cargo.arg("--")
518518
.arg("--markdown-css").arg("rust.css")
519519
.arg("--markdown-no-toc")
520+
.arg("--generate-redirect-pages")
520521
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
521522

522523
builder.run(&mut cargo);
@@ -581,7 +582,9 @@ impl Step for Test {
581582
let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
582583
compile::test_cargo(builder, &compiler, target, &mut cargo);
583584

584-
cargo.arg("--no-deps").arg("-p").arg("test");
585+
cargo.arg("--no-deps")
586+
.arg("-p").arg("test")
587+
.env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1");
585588

586589
builder.run(&mut cargo);
587590
builder.cp_r(&my_out, &out);
@@ -650,9 +653,9 @@ impl Step for WhitelistedRustc {
650653
// We don't want to build docs for internal compiler dependencies in this
651654
// step (there is another step for that). Therefore, we whitelist the crates
652655
// for which docs must be built.
653-
cargo.arg("--no-deps");
654656
for krate in &["proc_macro"] {
655-
cargo.arg("-p").arg(krate);
657+
cargo.arg("-p").arg(krate)
658+
.env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1");
656659
}
657660

658661
builder.run(&mut cargo);

src/librustdoc/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ pub struct RenderOptions {
192192
/// If false, the `select` element to have search filtering by crates on rendered docs
193193
/// won't be generated.
194194
pub generate_search_filter: bool,
195+
/// Option (disabled by default) to generate files used by RLS and some other tools.
196+
pub generate_redirect_pages: bool,
195197
}
196198

197199
impl Options {
@@ -436,6 +438,7 @@ impl Options {
436438
let static_root_path = matches.opt_str("static-root-path");
437439
let generate_search_filter = !matches.opt_present("disable-per-crate-search");
438440
let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
441+
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
439442

440443
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
441444

@@ -480,6 +483,7 @@ impl Options {
480483
markdown_css,
481484
markdown_playground_url,
482485
generate_search_filter,
486+
generate_redirect_pages,
483487
}
484488
})
485489
}

src/librustdoc/html/render.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ struct SharedContext {
148148
/// If false, the `select` element to have search filtering by crates on rendered docs
149149
/// won't be generated.
150150
pub generate_search_filter: bool,
151+
/// Option disabled by default to generate files used by RLS and some other tools.
152+
pub generate_redirect_pages: bool,
151153
}
152154

153155
impl SharedContext {
@@ -516,6 +518,7 @@ pub fn run(mut krate: clean::Crate,
516518
resource_suffix,
517519
static_root_path,
518520
generate_search_filter,
521+
generate_redirect_pages,
519522
..
520523
} = options;
521524

@@ -545,6 +548,7 @@ pub fn run(mut krate: clean::Crate,
545548
resource_suffix,
546549
static_root_path,
547550
generate_search_filter,
551+
generate_redirect_pages,
548552
};
549553

550554
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -2246,17 +2250,18 @@ impl Context {
22462250
if !self.render_redirect_pages {
22472251
all.append(full_path(self, &item), &item_type);
22482252
}
2249-
// Redirect from a sane URL using the namespace to Rustdoc's
2250-
// URL for the page.
2251-
let redir_name = format!("{}.{}.html", name, item_type.name_space());
2252-
let redir_dst = self.dst.join(redir_name);
2253-
if let Ok(redirect_out) = OpenOptions::new().create_new(true)
2254-
.write(true)
2255-
.open(&redir_dst) {
2256-
let mut redirect_out = BufWriter::new(redirect_out);
2257-
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
2253+
if self.shared.generate_redirect_pages {
2254+
// Redirect from a sane URL using the namespace to Rustdoc's
2255+
// URL for the page.
2256+
let redir_name = format!("{}.{}.html", name, item_type.name_space());
2257+
let redir_dst = self.dst.join(redir_name);
2258+
if let Ok(redirect_out) = OpenOptions::new().create_new(true)
2259+
.write(true)
2260+
.open(&redir_dst) {
2261+
let mut redirect_out = BufWriter::new(redirect_out);
2262+
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
2263+
}
22582264
}
2259-
22602265
// If the item is a macro, redirect from the old macro URL (with !)
22612266
// to the new one (without).
22622267
if item_type == ItemType::Macro {

src/librustdoc/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ fn opts() -> Vec<RustcOptGroup> {
345345
"Directory to persist doctest executables into",
346346
"PATH")
347347
}),
348+
unstable("generate-redirect-pages", |o| {
349+
o.optflag("",
350+
"generate-redirect-pages",
351+
"Generate extra pages to support legacy URLs and tool links")
352+
}),
348353
]
349354
}
350355

src/test/rustdoc/issue-19190.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags:-Z unstable-options --generate-redirect-pages
2+
13
use std::ops::Deref;
24

35
pub struct Foo;

src/test/rustdoc/issue-21092.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
extern crate issue_21092;
55

6-
// @has issue_21092/Bar.t.html
76
// @has issue_21092/struct.Bar.html
87
// @has - '//*[@id="associatedtype.Bar"]' 'type Bar = i32'
98
pub use issue_21092::{Foo, Bar};

src/test/rustdoc/issue-35169-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ impl DerefMut for Bar {
2323
fn deref_mut(&mut self) -> &mut Foo { loop {} }
2424
}
2525

26-
// @has issue_35169_2/Bar.t.html
2726
// @has issue_35169_2/struct.Bar.html
2827
// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)'
2928
// @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)'

src/test/rustdoc/issue-35169.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ impl Deref for Bar {
1818
fn deref(&self) -> &Foo { loop {} }
1919
}
2020

21-
// @has issue_35169/Bar.t.html
2221
// @has issue_35169/struct.Bar.html
2322
// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)'
2423
// @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)'

src/test/rustdoc/macros.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// @has - //pre '() => { ... };'
33
// @has - //pre '($a:tt) => { ... };'
44
// @has - //pre '($e:expr) => { ... };'
5-
// @has macros/macro.my_macro!.html
6-
// @has - //a 'macro.my_macro.html'
75
#[macro_export]
86
macro_rules! my_macro {
97
() => [];

src/test/rustdoc/src-links.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ pub mod bar {
1414
// @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html'
1515
pub mod baz {
1616
/// Dox
17-
// @has foo/bar/baz/baz.v.html
1817
// @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html'
1918
pub fn baz() { }
2019
}
2120

2221
/// Dox
23-
// @has foo/bar/Foobar.t.html
2422
// @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html'
2523
pub trait Foobar { fn dummy(&self) { } }
2624

src/test/rustdoc/structfields.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags:-Z unstable-options --generate-redirect-pages
2+
13
// @has structfields/Foo.t.html
24
// @has - struct.Foo.html
35
// @has structfields/struct.Foo.html

src/test/rustdoc/without-redirect.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/macro.bar.html
4+
// @has foo/macro.bar!.html
5+
// @!has foo/bar.m.html
6+
#[macro_export]
7+
macro_rules! bar {
8+
() => {}
9+
}
10+
11+
// @has foo/struct.Bar.html
12+
// @!has foo/Bar.t.html
13+
pub struct Bar;

0 commit comments

Comments
 (0)