@@ -94,7 +94,9 @@ use std::cmp::max;
9494use std:: default:: Default ;
9595use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
9696use std:: env;
97+ use std:: error:: Error ;
9798use std:: ffi:: OsString ;
99+ use std:: fmt:: { self , Display } ;
98100use std:: io:: { self , Read , Write } ;
99101use std:: iter:: repeat;
100102use std:: mem;
@@ -146,6 +148,12 @@ pub mod target_features {
146148 }
147149}
148150
151+ /// Exit status code used for successful compilation and help output.
152+ pub const EXIT_SUCCESS : isize = 0 ;
153+
154+ /// Exit status code used for compilation failures and invalid flags.
155+ pub const EXIT_FAILURE : isize = 1 ;
156+
149157const BUG_REPORT_URL : & ' static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
150158 md#bug-reports";
151159
@@ -178,7 +186,7 @@ pub fn abort_on_err<T>(result: Result<T, CompileIncomplete>, sess: &Session) ->
178186pub fn run < F > ( run_compiler : F ) -> isize
179187 where F : FnOnce ( ) -> ( CompileResult , Option < Session > ) + Send + ' static
180188{
181- monitor ( move || {
189+ let result = monitor ( move || {
182190 let ( result, session) = run_compiler ( ) ;
183191 if let Err ( CompileIncomplete :: Errored ( _) ) = result {
184192 match session {
@@ -201,7 +209,11 @@ pub fn run<F>(run_compiler: F) -> isize
201209 }
202210 }
203211 } ) ;
204- 0
212+
213+ match result {
214+ Ok ( ( ) ) => EXIT_SUCCESS ,
215+ Err ( _) => EXIT_FAILURE ,
216+ }
205217}
206218
207219fn load_backend_from_dylib ( path : & Path ) -> fn ( ) -> Box < dyn CodegenBackend > {
@@ -1625,20 +1637,30 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
16251637 }
16261638}
16271639
1640+ #[ derive( Debug ) ]
1641+ pub struct CompilationFailure ;
1642+
1643+ impl Error for CompilationFailure { }
1644+
1645+ impl Display for CompilationFailure {
1646+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1647+ write ! ( f, "compilation had errors" )
1648+ }
1649+ }
1650+
16281651/// Run a procedure which will detect panics in the compiler and print nicer
16291652/// error messages rather than just failing the test.
16301653///
16311654/// The diagnostic emitter yielded to the procedure should be used for reporting
16321655/// errors of the compiler.
1633- pub fn monitor < F : FnOnce ( ) + Send + ' static > ( f : F ) {
1634- let result = in_rustc_thread ( move || {
1656+ pub fn monitor < F : FnOnce ( ) + Send + ' static > ( f : F ) -> Result < ( ) , CompilationFailure > {
1657+ in_rustc_thread ( move || {
16351658 f ( )
1636- } ) ;
1637-
1638- if let Err ( value) = result {
1639- // Thread panicked without emitting a fatal diagnostic
1640- if !value. is :: < errors:: FatalErrorMarker > ( ) {
1641- // Emit a newline
1659+ } ) . map_err ( |value| {
1660+ if value. is :: < errors:: FatalErrorMarker > ( ) {
1661+ CompilationFailure
1662+ } else {
1663+ // Thread panicked without emitting a fatal diagnostic
16421664 eprintln ! ( "" ) ;
16431665
16441666 let emitter =
@@ -1677,10 +1699,10 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
16771699 & note,
16781700 errors:: Level :: Note ) ;
16791701 }
1680- }
16811702
1682- panic:: resume_unwind ( Box :: new ( errors:: FatalErrorMarker ) ) ;
1683- }
1703+ panic:: resume_unwind ( Box :: new ( errors:: FatalErrorMarker ) ) ;
1704+ }
1705+ } )
16841706}
16851707
16861708pub fn diagnostics_registry ( ) -> errors:: registry:: Registry {
0 commit comments