Add wrapper type for ExitCode for use in RanlibFailure

This commit is contained in:
Ellis Hoag 2022-08-31 22:02:35 -07:00
parent fb488ad366
commit e906ea80fe
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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)]