Skip to content

Commit c3c4615

Browse files
QuietMisdreavuspietroalbini
authored andcommitted
rustdoc: set panic output before starting compiler thread pool
1 parent 5e53528 commit c3c4615

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/librustdoc/test.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -232,40 +232,42 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
232232
..config::basic_options().clone()
233233
};
234234

235-
let (libdir, outdir) = driver::spawn_thread_pool(sessopts, |sessopts| {
236-
// Shuffle around a few input and output handles here. We're going to pass
237-
// an explicit handle into rustc to collect output messages, but we also
238-
// want to catch the error message that rustc prints when it fails.
239-
//
240-
// We take our thread-local stderr (likely set by the test runner) and replace
241-
// it with a sink that is also passed to rustc itself. When this function
242-
// returns the output of the sink is copied onto the output of our own thread.
243-
//
244-
// The basic idea is to not use a default Handler for rustc, and then also
245-
// not print things by default to the actual stderr.
246-
struct Sink(Arc<Mutex<Vec<u8>>>);
247-
impl Write for Sink {
248-
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
249-
Write::write(&mut *self.0.lock().unwrap(), data)
250-
}
251-
fn flush(&mut self) -> io::Result<()> { Ok(()) }
235+
// Shuffle around a few input and output handles here. We're going to pass
236+
// an explicit handle into rustc to collect output messages, but we also
237+
// want to catch the error message that rustc prints when it fails.
238+
//
239+
// We take our thread-local stderr (likely set by the test runner) and replace
240+
// it with a sink that is also passed to rustc itself. When this function
241+
// returns the output of the sink is copied onto the output of our own thread.
242+
//
243+
// The basic idea is to not use a default Handler for rustc, and then also
244+
// not print things by default to the actual stderr.
245+
struct Sink(Arc<Mutex<Vec<u8>>>);
246+
impl Write for Sink {
247+
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
248+
Write::write(&mut *self.0.lock().unwrap(), data)
252249
}
253-
struct Bomb(Arc<Mutex<Vec<u8>>>, Box<Write+Send>);
254-
impl Drop for Bomb {
255-
fn drop(&mut self) {
256-
let _ = self.1.write_all(&self.0.lock().unwrap());
257-
}
250+
fn flush(&mut self) -> io::Result<()> { Ok(()) }
251+
}
252+
struct Bomb(Arc<Mutex<Vec<u8>>>, Box<Write+Send>);
253+
impl Drop for Bomb {
254+
fn drop(&mut self) {
255+
let _ = self.1.write_all(&self.0.lock().unwrap());
258256
}
259-
let data = Arc::new(Mutex::new(Vec::new()));
257+
}
258+
let data = Arc::new(Mutex::new(Vec::new()));
259+
260+
let old = io::set_panic(Some(box Sink(data.clone())));
261+
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
262+
263+
let (libdir, outdir) = driver::spawn_thread_pool(sessopts, |sessopts| {
260264
let codemap = Lrc::new(CodeMap::new_doctest(
261265
sessopts.file_path_mapping(), filename.clone(), line as isize - line_offset as isize
262266
));
263267
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()),
264268
Some(codemap.clone()),
265269
false,
266270
false);
267-
let old = io::set_panic(Some(box Sink(data.clone())));
268-
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
269271

270272
// Compile the code
271273
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);

0 commit comments

Comments
 (0)