Skip to content

Commit 425b5f4

Browse files
QuietMisdreavuspietroalbini
authored andcommitted
force the doctest rustc thread to share the name of the test
1 parent 51847e3 commit 425b5f4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/librustc_driver/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,12 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
14831483
}
14841484
}
14851485

1486-
/// Runs `f` in a suitable thread for running `rustc`; returns a
1487-
/// `Result` with either the return value of `f` or -- if a panic
1488-
/// occurs -- the panic value.
1489-
pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
1486+
/// Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return
1487+
/// value of `f` or -- if a panic occurs -- the panic value.
1488+
///
1489+
/// This version applies the given name to the thread. This is used by rustdoc to ensure consistent
1490+
/// doctest output across platforms and executions.
1491+
pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<Any + Send>>
14901492
where F: FnOnce() -> R + Send + 'static,
14911493
R: Send + 'static,
14921494
{
@@ -1530,7 +1532,7 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
15301532

15311533
// The or condition is added from backward compatibility.
15321534
if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() {
1533-
let mut cfg = thread::Builder::new().name("rustc".to_string());
1535+
let mut cfg = thread::Builder::new().name(name);
15341536

15351537
// FIXME: Hacks on hacks. If the env is trying to override the stack size
15361538
// then *don't* set it explicitly.
@@ -1546,6 +1548,16 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
15461548
}
15471549
}
15481550

1551+
/// Runs `f` in a suitable thread for running `rustc`; returns a
1552+
/// `Result` with either the return value of `f` or -- if a panic
1553+
/// occurs -- the panic value.
1554+
pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
1555+
where F: FnOnce() -> R + Send + 'static,
1556+
R: Send + 'static,
1557+
{
1558+
in_named_rustc_thread("rustc".to_string(), f)
1559+
}
1560+
15491561
/// Get a list of extra command-line flags provided by the user, as strings.
15501562
///
15511563
/// This function is used during ICEs to show more information useful for

src/librustdoc/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl Collector {
548548
debug!("Creating test {}: {}", name, test);
549549
self.tests.push(testing::TestDescAndFn {
550550
desc: testing::TestDesc {
551-
name: testing::DynTestName(name),
551+
name: testing::DynTestName(name.clone()),
552552
ignore: should_ignore,
553553
// compiler failures are test failures
554554
should_panic: testing::ShouldPanic::No,
@@ -558,7 +558,7 @@ impl Collector {
558558
let panic = io::set_panic(None);
559559
let print = io::set_print(None);
560560
match {
561-
rustc_driver::in_rustc_thread(move || with_globals(move || {
561+
rustc_driver::in_named_rustc_thread(name, move || with_globals(move || {
562562
io::set_panic(panic);
563563
io::set_print(print);
564564
run_test(&test,

0 commit comments

Comments
 (0)