diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index aa313af94ca..1ba9dcaac1d 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -453,12 +453,10 @@ impl Options { && !matches.opt_present("show-coverage") && !nightly_options::is_unstable_enabled(matches) { - let extra = if format == "json" { - " (see https://github.com/rust-lang/rust/issues/76578)" - } else if format == "doctest" { - " (see https://github.com/rust-lang/rust/issues/134529)" - } else { - "" + let extra = match format { + "json" => " (see https://github.com/rust-lang/rust/issues/76578)", + "doctest" => " (see https://github.com/rust-lang/rust/issues/134529)", + _ => "", }; dcx.fatal( format!( diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 46d0776699a..8b522e614b8 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -211,15 +211,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions crate::wrap_return(dcx, generate_args_file(&args_path, &options)); let extract_doctests = options.output_format == OutputFormat::Doctest; - let CreateRunnableDocTests { - standalone_tests, - mergeable_tests, - rustdoc_options, - opts, - unused_extern_reports, - compiling_test_count, - .. - } = match interface::run_compiler(config, |compiler| { + let result = interface::run_compiler(config, |compiler| { let krate = rustc_interface::passes::parse(&compiler.sess); let collector = rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| { @@ -256,7 +248,17 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions compiler.sess.dcx().abort_if_errors(); collector - }) { + }); + + let CreateRunnableDocTests { + standalone_tests, + mergeable_tests, + rustdoc_options, + opts, + unused_extern_reports, + compiling_test_count, + .. + } = match result { Ok(Some(collector)) => collector, Ok(None) => return, Err(error) => { diff --git a/src/librustdoc/doctest/extracted.rs b/src/librustdoc/doctest/extracted.rs index b45cc907635..03c8814a4c9 100644 --- a/src/librustdoc/doctest/extracted.rs +++ b/src/librustdoc/doctest/extracted.rs @@ -1,14 +1,23 @@ +//! Rustdoc's doctest extraction. +//! +//! This module contains the logic to extract doctests and output a JSON containing this +//! information. + use serde::Serialize; use super::{DocTestBuilder, ScrapedDocTest}; use crate::config::Options as RustdocOptions; use crate::html::markdown; +/// The version of JSON output that this code generates. +/// +/// This integer is incremented with every breaking change to the API, +/// and is returned along with the JSON blob into the `format_version` root field. +/// Consuming code should assert that this value matches the format version(s) that it supports. const FORMAT_VERSION: u32 = 1; #[derive(Serialize)] pub(crate) struct ExtractedDocTests { - #[allow(non_snake_case)] format_version: u32, doctests: Vec, }