Skip to content

Commit 3b01f65

Browse files
committed
Diferentiate between ICE and compilation error
1 parent 2db01be commit 3b01f65

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_middle::mir::interpret::AllocId;
1818
use rustc_middle::ty::TyCtxt;
1919
use rustc_session::EarlyErrorHandler;
2020
pub use rustc_span::def_id::{CrateNum, DefId};
21-
use rustc_span::ErrorGuaranteed;
2221

2322
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
2423
let mut ret = None;
@@ -211,11 +210,14 @@ where
211210

212211
/// Runs the compiler against given target and tests it with `test_function`
213212
pub fn run(mut self) -> Result<T, CompilerError> {
214-
rustc_driver::catch_fatal_errors(|| {
215-
RunCompiler::new(&self.args.clone(), &mut self).run().unwrap();
216-
})
217-
.map_err(|e| <ErrorGuaranteed as Into<CompilerError>>::into(e))?;
218-
Ok(self.result.unwrap())
213+
let compiler_result = rustc_driver::catch_fatal_errors(|| {
214+
RunCompiler::new(&self.args.clone(), &mut self).run()
215+
});
216+
match compiler_result {
217+
Ok(Ok(())) => Ok(self.result.unwrap()),
218+
Ok(Err(_)) => Err(CompilerError::CompilationFailed),
219+
Err(_) => Err(CompilerError::ICE),
220+
}
219221
}
220222
}
221223

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,6 @@ impl<'tcx> Stable<'tcx> for rustc_span::Span {
14561456

14571457
impl From<ErrorGuaranteed> for CompilerError {
14581458
fn from(_error: ErrorGuaranteed) -> Self {
1459-
CompilerError
1459+
CompilerError::CompilationFailed
14601460
}
14611461
}

compiler/rustc_smir/src/stable_mir/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ pub type ImplTraitDecls = Vec<ImplDef>;
5858

5959
/// An error type used to represent an error that has already been reported by the compiler.
6060
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
61-
pub struct CompilerError;
61+
pub enum CompilerError {
62+
/// Internal compiler error (I.e.: Compiler crashed).
63+
ICE,
64+
/// Compilation failed.
65+
CompilationFailed,
66+
}
6267

6368
/// Holds information about a crate.
6469
#[derive(Clone, PartialEq, Eq, Debug)]

tests/ui-fulldeps/stable-mir/crate-info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn main() {
136136
CRATE_NAME.to_string(),
137137
path.to_string(),
138138
];
139-
rustc_internal::StableMir::new(args, test_stable_mir).run();
139+
rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap();
140140
}
141141

142142
fn generate_input(path: &str) -> std::io::Result<()> {

0 commit comments

Comments
 (0)