about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEllis Hoag <ellis.sparky.hoag@gmail.com>2022-08-31 22:02:35 -0700
committerEllis Hoag <ellis.sparky.hoag@gmail.com>2022-09-24 10:24:48 -0700
commite906ea80fef37b17ac7b3630f6b248fbb0927c49 (patch)
tree5cf546caa3e76b3a697f42e44ada4882487c22b0
parentfb488ad36605093d17ea22e9e533b2103559e376 (diff)
downloadrust-e906ea80fef37b17ac7b3630f6b248fbb0927c49.tar.gz
rust-e906ea80fef37b17ac7b3630f6b248fbb0927c49.zip
Add wrapper type for ExitCode for use in RanlibFailure
-rw-r--r--compiler/rustc_codegen_gcc/src/archive.rs2
-rw-r--r--compiler/rustc_codegen_gcc/src/errors.rs24
2 files changed, 24 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_gcc/src/archive.rs b/compiler/rustc_codegen_gcc/src/archive.rs
index 77fbb2c500e..ac0342f6b80 100644
--- a/compiler/rustc_codegen_gcc/src/archive.rs
+++ b/compiler/rustc_codegen_gcc/src/archive.rs
@@ -183,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
             std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib");
 
         if !status.success() {
-            self.config.sess.emit_fatal(RanlibFailure { exit_code: format!("{:?}", status.code()) });
+            self.config.sess.emit_fatal(RanlibFailure::new(status.code()));
         }
 
         any_members
diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs
index 01de75976a3..b5fc789c279 100644
--- a/compiler/rustc_codegen_gcc/src/errors.rs
+++ b/compiler/rustc_codegen_gcc/src/errors.rs
@@ -1,10 +1,32 @@
+use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
 use rustc_macros::SessionDiagnostic;
 use rustc_span::Span;
+use std::borrow::Cow;
+
+struct ExitCode {
+    pub exit_code: Option<i32>,
+}
+
+impl IntoDiagnosticArg for ExitCode {
+    fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+        match self.exit_code {
+            Some(t) => t.into_diagnostic_arg(),
+            None => DiagnosticArgValue::Str(Cow::Borrowed("None")),
+        }
+    }
+}
 
 #[derive(SessionDiagnostic)]
 #[diag(codegen_gcc::ranlib_failure)]
 pub(crate) struct RanlibFailure {
-    pub exit_code: String,
+    exit_code: ExitCode,
+}
+
+impl RanlibFailure {
+    pub fn new(exit_code: Option<i32>) -> Self {
+        let exit_code = ExitCode{ exit_code };
+        RanlibFailure { exit_code }
+    }
 }
 
 #[derive(SessionDiagnostic)]