1
Fork 0

Improve code and add missing docs for new doctest::extracted module

This commit is contained in:
Guillaume Gomez 2025-01-29 14:18:37 +01:00
parent 07c878910b
commit a5d66e07e1
3 changed files with 26 additions and 17 deletions

View file

@ -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!(

View file

@ -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) => {

View file

@ -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>,
}