From b30cc1ef494a224b4e817ece96155fd3417f53fb Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 2 Mar 2025 14:33:29 -0700 Subject: [PATCH] doctests: fix merging on stable Fixes #137898 The generated multi-test harness relies on nightly-only APIs, so the only way to run it on stable is to enable them. Since tests that use crate attrs don't be merged, there's no way to use nightly-only features on it anyway. (cherry picked from commit 5d6eeea5f969a5a3478de3904e9e02df68ce8b89) --- src/librustdoc/doctest.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 009e9662933a..91794cc37b5e 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -525,7 +525,12 @@ fn run_test( } compiler.arg("--edition").arg(doctest.edition.to_string()); - if !doctest.is_multiple_tests { + if doctest.is_multiple_tests { + // The merged test harness uses the `test` crate, so we need to actually allow it. + // This will not expose nightly features on stable, because crate attrs disable + // merging, and `#![feature]` is required to be a crate attr. + compiler.env("RUSTC_BOOTSTRAP", "1"); + } else { // Setting these environment variables is unneeded if this is a merged doctest. compiler.env("UNSTABLE_RUSTDOC_TEST_PATH", &doctest.test_opts.path); compiler.env(