Diferentiate between ICE and compilation error
This commit is contained in:
parent
2db01be584
commit
3b01f65aa5
4 changed files with 16 additions and 9 deletions
|
@ -18,7 +18,6 @@ use rustc_middle::mir::interpret::AllocId;
|
|||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::EarlyErrorHandler;
|
||||
pub use rustc_span::def_id::{CrateNum, DefId};
|
||||
use rustc_span::ErrorGuaranteed;
|
||||
|
||||
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
|
||||
let mut ret = None;
|
||||
|
@ -211,11 +210,14 @@ where
|
|||
|
||||
/// Runs the compiler against given target and tests it with `test_function`
|
||||
pub fn run(mut self) -> Result<T, CompilerError> {
|
||||
rustc_driver::catch_fatal_errors(|| {
|
||||
RunCompiler::new(&self.args.clone(), &mut self).run().unwrap();
|
||||
})
|
||||
.map_err(|e| <ErrorGuaranteed as Into<CompilerError>>::into(e))?;
|
||||
Ok(self.result.unwrap())
|
||||
let compiler_result = rustc_driver::catch_fatal_errors(|| {
|
||||
RunCompiler::new(&self.args.clone(), &mut self).run()
|
||||
});
|
||||
match compiler_result {
|
||||
Ok(Ok(())) => Ok(self.result.unwrap()),
|
||||
Ok(Err(_)) => Err(CompilerError::CompilationFailed),
|
||||
Err(_) => Err(CompilerError::ICE),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1456,6 +1456,6 @@ impl<'tcx> Stable<'tcx> for rustc_span::Span {
|
|||
|
||||
impl From<ErrorGuaranteed> for CompilerError {
|
||||
fn from(_error: ErrorGuaranteed) -> Self {
|
||||
CompilerError
|
||||
CompilerError::CompilationFailed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,12 @@ pub type ImplTraitDecls = Vec<ImplDef>;
|
|||
|
||||
/// An error type used to represent an error that has already been reported by the compiler.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct CompilerError;
|
||||
pub enum CompilerError {
|
||||
/// Internal compiler error (I.e.: Compiler crashed).
|
||||
ICE,
|
||||
/// Compilation failed.
|
||||
CompilationFailed,
|
||||
}
|
||||
|
||||
/// Holds information about a crate.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
|
|
@ -136,7 +136,7 @@ fn main() {
|
|||
CRATE_NAME.to_string(),
|
||||
path.to_string(),
|
||||
];
|
||||
rustc_internal::StableMir::new(args, test_stable_mir).run();
|
||||
rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap();
|
||||
}
|
||||
|
||||
fn generate_input(path: &str) -> std::io::Result<()> {
|
||||
|
|
Loading…
Add table
Reference in a new issue