Replace spaghetti with a simple errors enum
This commit is contained in:
parent
3f883b850d
commit
bf7ce6a1a6
7 changed files with 65 additions and 77 deletions
|
@ -18,7 +18,7 @@ extern crate tracing;
|
|||
pub extern crate rustc_plugin_impl as plugin;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenResults};
|
||||
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
|
||||
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
||||
use rustc_data_structures::sync::SeqCst;
|
||||
use rustc_errors::registry::{InvalidErrorCode, Registry};
|
||||
|
@ -60,7 +60,10 @@ pub mod args;
|
|||
pub mod pretty;
|
||||
mod session_diagnostics;
|
||||
|
||||
use crate::session_diagnostics::{RlinkNotAFile, RlinkUnableToDeserialize, RlinkUnableToRead};
|
||||
use crate::session_diagnostics::{
|
||||
RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch,
|
||||
RLinkWrongFileType, RlinkNotAFile, RlinkUnableToRead,
|
||||
};
|
||||
|
||||
/// Exit status code used for successful compilation and help output.
|
||||
pub const EXIT_SUCCESS: i32 = 0;
|
||||
|
@ -591,7 +594,24 @@ pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Comp
|
|||
let codegen_results = match CodegenResults::deserialize_rlink(rlink_data) {
|
||||
Ok(codegen) => codegen,
|
||||
Err(err) => {
|
||||
sess.emit_fatal(RlinkUnableToDeserialize { err });
|
||||
match err {
|
||||
CodegenErrors::WrongFileType => sess.emit_fatal(RLinkWrongFileType),
|
||||
CodegenErrors::EmptyVersionNumber => {
|
||||
sess.emit_fatal(RLinkEmptyVersionNumber)
|
||||
}
|
||||
CodegenErrors::EncodingVersionMismatch { version_array, rlink_version } => {
|
||||
sess.emit_fatal(RLinkEncodingVersionMismatch {
|
||||
version_array,
|
||||
rlink_version,
|
||||
})
|
||||
}
|
||||
CodegenErrors::RustcVersionMismatch { rustc_version, current_version } => {
|
||||
sess.emit_fatal(RLinkRustcVersionMismatch {
|
||||
rustc_version,
|
||||
current_version,
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
let result = compiler.codegen_backend().link(sess, codegen_results, &outputs);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use rustc_codegen_ssa::session_diagnostic::DeserializeRlinkError;
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
|
@ -8,9 +7,25 @@ pub(crate) struct RlinkUnableToRead {
|
|||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(driver::rlink_unable_to_deserialize)]
|
||||
pub(crate) struct RlinkUnableToDeserialize {
|
||||
pub err: DeserializeRlinkError,
|
||||
#[diag(driver::rlink_wrong_file_type)]
|
||||
pub(crate) struct RLinkWrongFileType;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(driver::rlink_empty_version_number)]
|
||||
pub(crate) struct RLinkEmptyVersionNumber;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(driver::rlink_encoding_version_mismatch)]
|
||||
pub(crate) struct RLinkEncodingVersionMismatch {
|
||||
pub version_array: String,
|
||||
pub rlink_version: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(driver::rlink_rustc_version_mismatch)]
|
||||
pub(crate) struct RLinkRustcVersionMismatch {
|
||||
pub rustc_version: String,
|
||||
pub current_version: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue