Skip to content

Commit 966fdf1

Browse files
committed
Auto merge of #46883 - QuietMisdreavus:faildown, r=GuillaumeGomez
rustdoc: add option to abort the process on markdown differences In the efforts of keeping the std docs free of markdown warnings, this PR adds a stopgap measure to make sure the CI fails if it detects a markdown difference. It does this by adding a new unstable flag to rustdoc, `--deny-render-differences`, which bootstrap then passes to rustdoc when documenting std and friends. The implementation is... probably not the cleanest option. It currently adds an extra branch after it prints the markdown warnings, which just prints a final line and calls `::std::process::abort(1)`. I did it like this because if it just panics regularly, it looks like an ICE, an even though `html::render::run` returns a Result, that Result is also just `expect`ed immediately, generating the same problem. This way bypasses the panic handler at the top of the thread and looks like a proper failure. Since i don't have a real error Handler there, this is the best i can do without pulling in a real error system for rustdoc. This PR is blocked on #46853, which will fix the rendering differences that were present on master when i started this branch.
2 parents ec9be91 + dfbb946 commit 966fdf1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/bootstrap/bin/rustdoc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ fn main() {
5757
// This "unstable-options" can be removed when `--crate-version` is stabilized
5858
cmd.arg("-Z").arg("unstable-options")
5959
.arg("--crate-version").arg(version);
60+
61+
// While we can assume that `-Z unstable-options` is set, let's also force rustdoc to panic
62+
// if pulldown rendering differences are found
63+
cmd.arg("--deny-render-differences");
6064
}
6165

6266
std::process::exit(match cmd.status() {

src/librustdoc/html/render.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ pub fn run(mut krate: clean::Crate,
495495
css_file_extension: Option<PathBuf>,
496496
renderinfo: RenderInfo,
497497
render_type: RenderType,
498-
sort_modules_alphabetically: bool) -> Result<(), Error> {
498+
sort_modules_alphabetically: bool,
499+
deny_render_differences: bool) -> Result<(), Error> {
499500
let src_root = match krate.src {
500501
FileName::Real(ref p) => match p.parent() {
501502
Some(p) => p.to_path_buf(),
@@ -659,6 +660,11 @@ pub fn run(mut krate: clean::Crate,
659660
render_difference(d, &mut intro_msg, span, text);
660661
}
661662
}
663+
664+
if deny_render_differences {
665+
println!("Aborting with {} rendering differences", markdown_warnings.len());
666+
::std::process::exit(1);
667+
}
662668
}
663669

664670
result

src/librustdoc/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ pub fn opts() -> Vec<RustcOptGroup> {
257257
o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \
258258
program, rather than alphabetically")
259259
}),
260+
unstable("deny-render-differences", |o| {
261+
o.optflag("", "deny-render-differences", "abort doc runs when markdown rendering \
262+
differences are found")
263+
}),
260264
]
261265
}
262266

@@ -393,6 +397,7 @@ pub fn main_args(args: &[String]) -> isize {
393397
}
394398

395399
let output_format = matches.opt_str("w");
400+
let deny_render_differences = matches.opt_present("deny-render-differences");
396401
let res = acquire_input(PathBuf::from(input), externs, &matches, move |out| {
397402
let Output { krate, passes, renderinfo } = out;
398403
info!("going to format");
@@ -404,7 +409,8 @@ pub fn main_args(args: &[String]) -> isize {
404409
css_file_extension,
405410
renderinfo,
406411
render_type,
407-
sort_modules_alphabetically)
412+
sort_modules_alphabetically,
413+
deny_render_differences)
408414
.expect("failed to generate documentation");
409415
0
410416
}

0 commit comments

Comments
 (0)