From aa909a00cf5a0969e847f0950b66bb998d1b9aff Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 12 Oct 2026 19:15:26 +0200 Subject: [PATCH 1/3] Test the interaction between `--remap-path-prefix` and doctests --- .../remap-path-prefix-doctest-panic/rmake.rs | 52 +++++++++++++++++++ .../src/doctest.rs | 4 ++ 2 files changed, 56 insertions(+) create mode 100644 tests/run-make/remap-path-prefix-doctest-panic/rmake.rs create mode 100644 tests/run-make/remap-path-prefix-doctest-panic/src/doctest.rs diff --git a/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs new file mode 100644 index 0000000000000..b184eda0b37bb --- /dev/null +++ b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs @@ -0,0 +1,52 @@ +// Checks that the location printed by a panicking doctest is remapped +// according to `--remap-path-scope`. +// +// Only the lines between the start of the stack backtrace and the end are +// are inspected, so timings, temp dirs and backtraces can't leak into the check. + +use run_make_support::assertion_helpers::{assert_contains, assert_not_contains}; +use run_make_support::rustdoc; + +/// Runs the failing doctest and returns stdout. +fn panic_file(scope: Option<&str>) -> String { + let mut cmd = rustdoc(); + cmd.input("src/doctest.rs") + .arg("--test") + .arg("--remap-path-prefix=src=/REMAPPED") + .arg("-Cdebuginfo=1") + .arg("--edition=2015") + .env("RUST_BACKTRACE", "1"); + + if let Some(scope) = scope { + cmd.arg(format!("--remap-path-scope={scope}")).arg("-Zunstable-options"); + } + + let out = cmd.run_fail(); + out.assert_stdout_contains("explicit panic"); + + let stdout = out.stdout_utf8(); + let section: Vec<&str> = stdout + .lines() + .skip_while(|l| l.trim() != "stack backtrace:") + .skip(1) + .take_while(|l| l.trim() != "failures:") + .collect(); + + assert!(!section.is_empty(), "no backtrace found in output:\n{stdout}"); + section.join("\n") +} + +fn main() { + // Check that with debuginfo (and related) we get the remapped path + for scope in [Some("debuginfo"), Some("object"), Some("all"), None] { + let stdout = panic_file(scope); + assert_contains(&stdout, "/REMAPPED/doctest.rs"); + assert_not_contains(&stdout, "src/doctest.rs"); + } + + for scope in ["diagnostics", "documentation", "macro"] { + let stdout = panic_file(Some(scope)); + assert_contains(&stdout, "src/doctest.rs"); + assert_not_contains(&stdout, "/REMAPPED/doctest.rs"); + } +} diff --git a/tests/run-make/remap-path-prefix-doctest-panic/src/doctest.rs b/tests/run-make/remap-path-prefix-doctest-panic/src/doctest.rs new file mode 100644 index 0000000000000..2160cc21f6b42 --- /dev/null +++ b/tests/run-make/remap-path-prefix-doctest-panic/src/doctest.rs @@ -0,0 +1,4 @@ +/// ``` +/// panic!() +/// ``` +pub fn f() {} From 52d575da57529c244a472ff022cbd8a06e5a404a Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 13 Oct 2026 21:57:52 +0200 Subject: [PATCH 2/3] Ignore cross-compile as doctests don't always work when cross-compiled --- tests/run-make/remap-path-prefix-doctest-panic/rmake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs index b184eda0b37bb..383955a270ab3 100644 --- a/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs +++ b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs @@ -4,6 +4,8 @@ // Only the lines between the start of the stack backtrace and the end are // are inspected, so timings, temp dirs and backtraces can't leak into the check. +//@ ignore-cross-compile + use run_make_support::assertion_helpers::{assert_contains, assert_not_contains}; use run_make_support::rustdoc; From ae4e708a534a4502ed517c32814b9722573812f9 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 15 Oct 2026 18:46:13 +0200 Subject: [PATCH 3/3] Also ignore Windows and mingw due to path handling differences --- tests/run-make/remap-path-prefix-doctest-panic/rmake.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs index 383955a270ab3..058f62e980fef 100644 --- a/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs +++ b/tests/run-make/remap-path-prefix-doctest-panic/rmake.rs @@ -5,6 +5,7 @@ // are inspected, so timings, temp dirs and backtraces can't leak into the check. //@ ignore-cross-compile +//@ ignore-windows use run_make_support::assertion_helpers::{assert_contains, assert_not_contains}; use run_make_support::rustdoc;