about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2025-03-02 14:33:29 -0700
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-03-10 01:43:14 +0100
commit5d6eeea5f969a5a3478de3904e9e02df68ce8b89 (patch)
tree67ba68b7b902be70721a122b8e6c6863725f31ec
parent3ea711f17e3946ac3f4df11691584e2c56b4b0cf (diff)
downloadrust-5d6eeea5f969a5a3478de3904e9e02df68ce8b89.tar.gz
rust-5d6eeea5f969a5a3478de3904e9e02df68ce8b89.zip
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.
-rw-r--r--src/librustdoc/doctest.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 3d6e0330fff..4f3b233f86e 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -550,7 +550,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(