From 76e33b4eb4f116b02d3754efd67e4fba0c9b3f93 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 24 Jul 2018 10:35:55 -0500 Subject: [PATCH] force the doctest rustc thread to share the name of the test --- src/librustc_driver/lib.rs | 22 +++++++++++++++++----- src/librustdoc/test.rs | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index f60954ea021..2100ceea228 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1497,10 +1497,12 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec(f: F) -> Result> +/// Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return +/// value of `f` or -- if a panic occurs -- the panic value. +/// +/// This version applies the given name to the thread. This is used by rustdoc to ensure consistent +/// doctest output across platforms and executions. +pub fn in_named_rustc_thread(name: String, f: F) -> Result> where F: FnOnce() -> R + Send + 'static, R: Send + 'static, { @@ -1564,7 +1566,7 @@ pub fn in_rustc_thread(f: F) -> Result> // The or condition is added from backward compatibility. if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() { - let mut cfg = thread::Builder::new().name("rustc".to_string()); + let mut cfg = thread::Builder::new().name(name); // FIXME: Hacks on hacks. If the env is trying to override the stack size // then *don't* set it explicitly. @@ -1580,6 +1582,16 @@ pub fn in_rustc_thread(f: F) -> Result> } } +/// Runs `f` in a suitable thread for running `rustc`; returns a +/// `Result` with either the return value of `f` or -- if a panic +/// occurs -- the panic value. +pub fn in_rustc_thread(f: F) -> Result> + where F: FnOnce() -> R + Send + 'static, + R: Send + 'static, +{ + in_named_rustc_thread("rustc".to_string(), f) +} + /// Get a list of extra command-line flags provided by the user, as strings. /// /// This function is used during ICEs to show more information useful for diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index c7d2e52e620..eb980a7369b 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -550,7 +550,7 @@ impl Collector { debug!("Creating test {}: {}", name, test); self.tests.push(testing::TestDescAndFn { desc: testing::TestDesc { - name: testing::DynTestName(name), + name: testing::DynTestName(name.clone()), ignore: should_ignore, // compiler failures are test failures should_panic: testing::ShouldPanic::No, @@ -560,7 +560,7 @@ impl Collector { let panic = io::set_panic(None); let print = io::set_print(None); match { - rustc_driver::in_rustc_thread(move || with_globals(move || { + rustc_driver::in_named_rustc_thread(name, move || with_globals(move || { io::set_panic(panic); io::set_print(print); hygiene::set_default_edition(edition);