about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-01-29 14:18:37 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-01-29 14:38:03 +0100
commita5d66e07e1775e3d5a9a8bb073fc50bf03101198 (patch)
tree4a435d33279fbf9747debe2229095601c973b18b
parent07c878910bd2243b67549808dc65e24a3e9c9528 (diff)
downloadrust-a5d66e07e1775e3d5a9a8bb073fc50bf03101198.tar.gz
rust-a5d66e07e1775e3d5a9a8bb073fc50bf03101198.zip
Improve code and add missing docs for new `doctest::extracted` module
-rw-r--r--src/librustdoc/config.rs10
-rw-r--r--src/librustdoc/doctest.rs22
-rw-r--r--src/librustdoc/doctest/extracted.rs11
3 files changed, 26 insertions, 17 deletions
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<ExtractedDocTest>,
 }