Skip to content

Commit a51b130

Browse files
Add --check option to rustdoc
1 parent f7801d6 commit a51b130

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/librustdoc/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ pub struct Options {
145145
pub render_options: RenderOptions,
146146
/// Output format rendering (used only for "show-coverage" option for the moment)
147147
pub output_format: Option<OutputFormat>,
148+
/// If this option is set to `true`, rustdoc will only run checks and not generate
149+
/// documentation.
150+
pub run_check: bool,
148151
}
149152

150153
impl fmt::Debug for Options {
@@ -185,6 +188,7 @@ impl fmt::Debug for Options {
185188
.field("runtool", &self.runtool)
186189
.field("runtool_args", &self.runtool_args)
187190
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
191+
.field("run_check", &self.run_check)
188192
.finish()
189193
}
190194
}
@@ -581,6 +585,7 @@ impl Options {
581585
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
582586
let document_private = matches.opt_present("document-private-items");
583587
let document_hidden = matches.opt_present("document-hidden-items");
588+
let run_check = matches.opt_present("check");
584589

585590
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
586591

@@ -616,6 +621,7 @@ impl Options {
616621
runtool_args,
617622
enable_per_target_ignores,
618623
test_builder,
624+
run_check,
619625
render_options: RenderOptions {
620626
output,
621627
external_html,

src/librustdoc/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ fn opts() -> Vec<RustcOptGroup> {
423423
"specified the rustc-like binary to use as the test builder",
424424
)
425425
}),
426+
unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
426427
]
427428
}
428429

@@ -514,6 +515,7 @@ fn main_options(options: config::Options) -> MainResult {
514515
// but we can't crates the Handler ahead of time because it's not Send
515516
let diag_opts = (options.error_format, options.edition, options.debugging_opts.clone());
516517
let show_coverage = options.show_coverage;
518+
let run_check = options.run_check;
517519

518520
// First, parse the crate and extract all relevant information.
519521
info!("starting to run rustc");
@@ -539,6 +541,9 @@ fn main_options(options: config::Options) -> MainResult {
539541
// if we ran coverage, bail early, we don't need to also generate docs at this point
540542
// (also we didn't load in any of the useful passes)
541543
return Ok(());
544+
} else if run_check {
545+
// Since we're in "check" mode, no need to generate anything beyond this point.
546+
return Ok(());
542547
}
543548

544549
info!("going to format");

0 commit comments

Comments
 (0)