From 9a8d6b8bb5dd7dd2d378849f0c2fa586e3a5b48b Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Sun, 21 Jan 2018 12:47:58 +0100 Subject: Do not capture stderr in the compiler. Instead just panic silently for fatal errors --- src/librustc_errors/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 1fb673815ee..33948ea92b9 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -19,6 +19,7 @@ #![cfg_attr(unix, feature(libc))] #![feature(conservative_impl_trait)] #![feature(i128_type)] +#![feature(optin_builtin_traits)] extern crate term; #[cfg(unix)] @@ -44,6 +45,7 @@ use std::rc::Rc; use std::{error, fmt}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; +use std::panic; mod diagnostic; mod diagnostic_builder; @@ -201,6 +203,18 @@ impl CodeSuggestion { #[must_use] pub struct FatalError; +pub struct FatalErrorMarker; + +// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError). +// We don't want to invoke the panic handler and print a backtrace for fatal errors. +impl !Send for FatalError {} + +impl FatalError { + pub fn raise(self) -> ! { + panic::resume_unwind(Box::new(FatalErrorMarker)) + } +} + impl fmt::Display for FatalError { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "parser fatal error") @@ -539,7 +553,7 @@ impl Handler { } } - panic!(self.fatal(&s)); + self.fatal(&s).raise(); } pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) { if lvl == Warning && !self.flags.can_emit_warnings { -- cgit 1.4.1-3-g733a5