Skip to content

Commit e906ea8

Browse files
committed
Add wrapper type for ExitCode for use in RanlibFailure
1 parent fb488ad commit e906ea8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/rustc_codegen_gcc/src/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
183183
std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib");
184184

185185
if !status.success() {
186-
self.config.sess.emit_fatal(RanlibFailure { exit_code: format!("{:?}", status.code()) });
186+
self.config.sess.emit_fatal(RanlibFailure::new(status.code()));
187187
}
188188

189189
any_members

compiler/rustc_codegen_gcc/src/errors.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1+
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
12
use rustc_macros::SessionDiagnostic;
23
use rustc_span::Span;
4+
use std::borrow::Cow;
5+
6+
struct ExitCode {
7+
pub exit_code: Option<i32>,
8+
}
9+
10+
impl IntoDiagnosticArg for ExitCode {
11+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
12+
match self.exit_code {
13+
Some(t) => t.into_diagnostic_arg(),
14+
None => DiagnosticArgValue::Str(Cow::Borrowed("None")),
15+
}
16+
}
17+
}
318

419
#[derive(SessionDiagnostic)]
520
#[diag(codegen_gcc::ranlib_failure)]
621
pub(crate) struct RanlibFailure {
7-
pub exit_code: String,
22+
exit_code: ExitCode,
23+
}
24+
25+
impl RanlibFailure {
26+
pub fn new(exit_code: Option<i32>) -> Self {
27+
let exit_code = ExitCode{ exit_code };
28+
RanlibFailure { exit_code }
29+
}
830
}
931

1032
#[derive(SessionDiagnostic)]

0 commit comments

Comments
 (0)