diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index 4496a58327e..1c5a0924f4a 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -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(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 { - rustc_driver::catch_fatal_errors(|| { - RunCompiler::new(&self.args.clone(), &mut self).run().unwrap(); - }) - .map_err(|e| >::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), + } } } diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 827b51e8a36..3909c3d85eb 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -1456,6 +1456,6 @@ impl<'tcx> Stable<'tcx> for rustc_span::Span { impl From for CompilerError { fn from(_error: ErrorGuaranteed) -> Self { - CompilerError + CompilerError::CompilationFailed } } diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 281d5aafb4c..bdbbab68e39 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -58,7 +58,12 @@ pub type ImplTraitDecls = Vec; /// 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)] diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs index 00dce3e004e..5439a884637 100644 --- a/tests/ui-fulldeps/stable-mir/crate-info.rs +++ b/tests/ui-fulldeps/stable-mir/crate-info.rs @@ -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<()> {