diff options
| author | Celina G. Val <celinval@amazon.com> | 2023-08-31 16:53:28 -0700 |
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2023-09-05 08:54:03 -0700 |
| commit | 3b01f65aa5cd19fe02b1bfd4e7e60390d8ef83fc (patch) | |
| tree | 58ca22fffd26722313a2353ef5fc512288cce0d1 | |
| parent | 2db01be5844ded1139eb4fb5f1434d0090b6ba38 (diff) | |
| download | rust-3b01f65aa5cd19fe02b1bfd4e7e60390d8ef83fc.tar.gz rust-3b01f65aa5cd19fe02b1bfd4e7e60390d8ef83fc.zip | |
Diferentiate between ICE and compilation error
| -rw-r--r-- | compiler/rustc_smir/src/rustc_internal/mod.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/mod.rs | 7 | ||||
| -rw-r--r-- | tests/ui-fulldeps/stable-mir/crate-info.rs | 2 |
4 files changed, 16 insertions, 9 deletions
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<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), + } } } 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<ErrorGuaranteed> 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<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)] 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<()> { |
