Skip to content

Commit b43c1d5

Browse files
authored
Rollup merge of #81495 - camelid:rustdoc-output_format-optional, r=GuillaumeGomez
rustdoc: Remove unnecessary optional Previously, the HTML output format was represented by both `Some(OutputFormat::Html)` and `None` so there's no need to have an optional. Instead, `OutputFormat::Html` is explicitly the default and we no longer have a "tri-state enum". r? `````@GuillaumeGomez`````
2 parents 774ba83 + f620b5c commit b43c1d5

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/librustdoc/config.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ crate enum OutputFormat {
3535
Html,
3636
}
3737

38+
impl Default for OutputFormat {
39+
fn default() -> OutputFormat {
40+
OutputFormat::Html
41+
}
42+
}
43+
3844
impl OutputFormat {
3945
crate fn is_json(&self) -> bool {
4046
matches!(self, OutputFormat::Json)
@@ -118,7 +124,7 @@ crate struct Options {
118124
crate enable_per_target_ignores: bool,
119125

120126
/// The path to a rustc-like binary to build tests with. If not set, we
121-
/// default to loading from $sysroot/bin/rustc.
127+
/// default to loading from `$sysroot/bin/rustc`.
122128
crate test_builder: Option<PathBuf>,
123129

124130
// Options that affect the documentation process
@@ -142,8 +148,10 @@ crate struct Options {
142148
crate crate_version: Option<String>,
143149
/// Collected options specific to outputting final pages.
144150
crate render_options: RenderOptions,
145-
/// Output format rendering (used only for "show-coverage" option for the moment)
146-
crate output_format: Option<OutputFormat>,
151+
/// The format that we output when rendering.
152+
///
153+
/// Currently used only for the `--show-coverage` option.
154+
crate output_format: OutputFormat,
147155
/// If this option is set to `true`, rustdoc will only run checks and not generate
148156
/// documentation.
149157
crate run_check: bool,
@@ -271,7 +279,7 @@ crate struct RenderInfo {
271279
crate deref_trait_did: Option<DefId>,
272280
crate deref_mut_trait_did: Option<DefId>,
273281
crate owned_box_did: Option<DefId>,
274-
crate output_format: Option<OutputFormat>,
282+
crate output_format: OutputFormat,
275283
}
276284

277285
impl Options {
@@ -537,28 +545,28 @@ impl Options {
537545

538546
let output_format = match matches.opt_str("output-format") {
539547
Some(s) => match OutputFormat::try_from(s.as_str()) {
540-
Ok(o) => {
541-
if o.is_json()
548+
Ok(out_fmt) => {
549+
if out_fmt.is_json()
542550
&& !(show_coverage || nightly_options::match_is_nightly_build(matches))
543551
{
544552
diag.struct_err("json output format isn't supported for doc generation")
545553
.emit();
546554
return Err(1);
547-
} else if !o.is_json() && show_coverage {
555+
} else if !out_fmt.is_json() && show_coverage {
548556
diag.struct_err(
549557
"html output format isn't supported for the --show-coverage option",
550558
)
551559
.emit();
552560
return Err(1);
553561
}
554-
Some(o)
562+
out_fmt
555563
}
556564
Err(e) => {
557565
diag.struct_err(&e).emit();
558566
return Err(1);
559567
}
560568
},
561-
None => None,
569+
None => OutputFormat::default(),
562570
};
563571
let crate_name = matches.opt_str("crate-name");
564572
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ crate fn run_global_ctxt(
463463
mut default_passes: passes::DefaultPassOption,
464464
mut manual_passes: Vec<String>,
465465
render_options: RenderOptions,
466-
output_format: Option<OutputFormat>,
466+
output_format: OutputFormat,
467467
) -> (clean::Crate, RenderInfo, RenderOptions) {
468468
// Certain queries assume that some checks were run elsewhere
469469
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),

src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ fn main_options(options: config::Options) -> MainResult {
578578
let (error_format, edition, debugging_options) = diag_opts;
579579
let diag = core::new_handler(error_format, None, &debugging_options);
580580
match output_format {
581-
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
581+
config::OutputFormat::Html => sess.time("render_html", || {
582582
run_renderer::<html::render::Context<'_>>(
583583
krate,
584584
render_opts,
@@ -588,7 +588,7 @@ fn main_options(options: config::Options) -> MainResult {
588588
tcx,
589589
)
590590
}),
591-
Some(config::OutputFormat::Json) => sess.time("render_json", || {
591+
config::OutputFormat::Json => sess.time("render_json", || {
592592
run_renderer::<json::JsonRenderer<'_>>(
593593
krate,
594594
render_opts,

src/librustdoc/passes/calculate_doc_coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'b> CoverageCalculator<'a, 'b> {
132132

133133
fn print_results(&self) {
134134
let output_format = self.ctx.renderinfo.borrow().output_format;
135-
if output_format.map(|o| o.is_json()).unwrap_or_else(|| false) {
135+
if output_format.is_json() {
136136
println!("{}", self.to_json());
137137
return;
138138
}

0 commit comments

Comments
 (0)