Skip to content

Commit 76e33b4

Browse files
force the doctest rustc thread to share the name of the test
1 parent e3bc713 commit 76e33b4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Diff for: src/librustc_driver/lib.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1497,10 +1497,12 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
14971497
}
14981498
}
14991499

1500-
/// Runs `f` in a suitable thread for running `rustc`; returns a
1501-
/// `Result` with either the return value of `f` or -- if a panic
1502-
/// occurs -- the panic value.
1503-
pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
1500+
/// Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return
1501+
/// value of `f` or -- if a panic occurs -- the panic value.
1502+
///
1503+
/// This version applies the given name to the thread. This is used by rustdoc to ensure consistent
1504+
/// doctest output across platforms and executions.
1505+
pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any + Send>>
15041506
where F: FnOnce() -> R + Send + 'static,
15051507
R: Send + 'static,
15061508
{
@@ -1564,7 +1566,7 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
15641566

15651567
// The or condition is added from backward compatibility.
15661568
if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() {
1567-
let mut cfg = thread::Builder::new().name("rustc".to_string());
1569+
let mut cfg = thread::Builder::new().name(name);
15681570

15691571
// FIXME: Hacks on hacks. If the env is trying to override the stack size
15701572
// then *don't* set it explicitly.
@@ -1580,6 +1582,16 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
15801582
}
15811583
}
15821584

1585+
/// Runs `f` in a suitable thread for running `rustc`; returns a
1586+
/// `Result` with either the return value of `f` or -- if a panic
1587+
/// occurs -- the panic value.
1588+
pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
1589+
where F: FnOnce() -> R + Send + 'static,
1590+
R: Send + 'static,
1591+
{
1592+
in_named_rustc_thread("rustc".to_string(), f)
1593+
}
1594+
15831595
/// Get a list of extra command-line flags provided by the user, as strings.
15841596
///
15851597
/// This function is used during ICEs to show more information useful for

Diff for: src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl Collector {
550550
debug!("Creating test {}: {}", name, test);
551551
self.tests.push(testing::TestDescAndFn {
552552
desc: testing::TestDesc {
553-
name: testing::DynTestName(name),
553+
name: testing::DynTestName(name.clone()),
554554
ignore: should_ignore,
555555
// compiler failures are test failures
556556
should_panic: testing::ShouldPanic::No,
@@ -560,7 +560,7 @@ impl Collector {
560560
let panic = io::set_panic(None);
561561
let print = io::set_print(None);
562562
match {
563-
rustc_driver::in_rustc_thread(move || with_globals(move || {
563+
rustc_driver::in_named_rustc_thread(name, move || with_globals(move || {
564564
io::set_panic(panic);
565565
io::set_print(print);
566566
hygiene::set_default_edition(edition);

0 commit comments

Comments
 (0)