]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #1366 - RalfJung:rustc-exit, r=RalfJung
authorbors <bors@rust-lang.org>
Sat, 25 Apr 2020 09:17:04 +0000 (09:17 +0000)
committerbors <bors@rust-lang.org>
Sat, 25 Apr 2020 09:17:04 +0000 (09:17 +0000)
fix exit code on rustc errors

Fixes https://github.com/rust-lang/miri/issues/1352

src/bin/miri.rs
tests/compile-fail/rustc-error.rs [new file with mode: 0644]

index 1ceb6e621a47b543e0ec0d59dbeca30d605da020..4e20e3a12da7e000e0d5940f14f04d422357516b 100644 (file)
@@ -259,6 +259,11 @@ fn main() {
     rustc_driver::install_ice_hook();
     let result = rustc_driver::catch_fatal_errors(move || {
         rustc_driver::run_compiler(&rustc_args, &mut MiriCompilerCalls { miri_config }, None, None)
-    });
-    std::process::exit(result.is_err() as i32);
+    })
+    .and_then(|result| result);
+    let exit_code = match result {
+        Ok(()) => rustc_driver::EXIT_SUCCESS,
+        Err(_) => rustc_driver::EXIT_FAILURE,
+    };
+    std::process::exit(exit_code);
 }
diff --git a/tests/compile-fail/rustc-error.rs b/tests/compile-fail/rustc-error.rs
new file mode 100644 (file)
index 0000000..3579a14
--- /dev/null
@@ -0,0 +1,4 @@
+// Make sure we exit with non-0 status code when the program fails to build.
+fn main() {
+    println("Hello, world!"); //~ ERROR expected function, found macro
+}