Skip to content

Commit 8341a7f

Browse files
authored
Unrolled build for rust-lang#121205
Rollup merge of rust-lang#121205 - nnethercote:fix-stable-mir-CompilerError, r=oli-obk Merge `CompilerError::CompilationFailed` and `CompilerError::ICE`. `CompilerError` has `CompilationFailed` and `ICE` variants, which seems reasonable at first. But the way it identifies them is flawed: - If compilation errors out, i.e. `RunCompiler::run` returns an `Err`, it uses `CompilationFailed`, which is reasonable. - If compilation panics with `FatalError`, it catches the panic and uses `ICE`. This is sometimes right, because ICEs do cause `FatalError` panics, but sometimes wrong, because certain compiler errors also cause `FatalError` panics. (The compiler/rustdoc/clippy/whatever just catches the `FatalError` with `catch_with_exit_code` in `main`.) In other words, certain non-ICE compilation failures get miscategorized as ICEs. It's not possible to reliably distinguish the two cases, so this commit merges them. It also renames the combined variant as just `Failed`, to better match the existing `Interrupted` and `Skipped` variants. Here is an example of a non-ICE failure that causes a `FatalError` panic, from `tests/ui/recursion_limit/issue-105700.rs`: ``` #![recursion_limit="4"] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] #![invalid_attribute] //~^ERROR recursion limit reached while expanding fn main() {{}} ``` r? ``@spastorino``
2 parents bcea3cb + e72e7e9 commit 8341a7f

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,14 @@ macro_rules! run_driver {
347347
Err(CompilerError::Interrupted(value))
348348
}
349349
(Ok(Ok(_)), None) => Err(CompilerError::Skipped),
350-
(Ok(Err(_)), _) => Err(CompilerError::CompilationFailed),
351-
(Err(_), _) => Err(CompilerError::ICE),
350+
// Two cases here:
351+
// - `run` finished normally and returned `Err`
352+
// - `run` panicked with `FatalErr`
353+
// You might think that normal compile errors cause the former, and
354+
// ICEs cause the latter. But some normal compiler errors also cause
355+
// the latter. So we can't meaningfully distinguish them, and group
356+
// them together.
357+
(Ok(Err(_)), _) | (Err(_), _) => Err(CompilerError::Failed),
352358
}
353359
}
354360
}

compiler/stable_mir/src/error.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ macro_rules! error {
1515
/// An error type used to represent an error that has already been reported by the compiler.
1616
#[derive(Clone, Copy, PartialEq, Eq)]
1717
pub enum CompilerError<T> {
18-
/// Internal compiler error (I.e.: Compiler crashed).
19-
ICE,
20-
/// Compilation failed.
21-
CompilationFailed,
18+
/// Compilation failed, either due to normal errors or ICE.
19+
Failed,
2220
/// Compilation was interrupted.
2321
Interrupted(T),
2422
/// Compilation skipped. This happens when users invoke rustc to retrieve information such as
@@ -54,8 +52,7 @@ where
5452
{
5553
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
5654
match self {
57-
CompilerError::ICE => write!(f, "Internal Compiler Error"),
58-
CompilerError::CompilationFailed => write!(f, "Compilation Failed"),
55+
CompilerError::Failed => write!(f, "Compilation Failed"),
5956
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason}"),
6057
CompilerError::Skipped => write!(f, "Compilation Skipped"),
6158
}
@@ -68,8 +65,7 @@ where
6865
{
6966
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
7067
match self {
71-
CompilerError::ICE => write!(f, "Internal Compiler Error"),
72-
CompilerError::CompilationFailed => write!(f, "Compilation Failed"),
68+
CompilerError::Failed => write!(f, "Compilation Failed"),
7369
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason:?}"),
7470
CompilerError::Skipped => write!(f, "Compilation Skipped"),
7571
}

tests/ui-fulldeps/stable-mir/compilation-result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn test_skipped(mut args: Vec<String>) {
5555
fn test_failed(mut args: Vec<String>) {
5656
args.push("--cfg=broken".to_string());
5757
let result = run!(args, || unreachable!() as ControlFlow<()>);
58-
assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed));
58+
assert_eq!(result, Err(stable_mir::CompilerError::Failed));
5959
}
6060

6161
/// Test that we are able to pass a closure and set the return according to the captured value.

0 commit comments

Comments
 (0)