mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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() {{}} ```
This commit is contained in:
parent
cefa14bf2f
commit
e72e7e9ae3
@ -347,8 +347,14 @@ macro_rules! run_driver {
|
|||||||
Err(CompilerError::Interrupted(value))
|
Err(CompilerError::Interrupted(value))
|
||||||
}
|
}
|
||||||
(Ok(Ok(_)), None) => Err(CompilerError::Skipped),
|
(Ok(Ok(_)), None) => Err(CompilerError::Skipped),
|
||||||
(Ok(Err(_)), _) => Err(CompilerError::CompilationFailed),
|
// Two cases here:
|
||||||
(Err(_), _) => Err(CompilerError::ICE),
|
// - `run` finished normally and returned `Err`
|
||||||
|
// - `run` panicked with `FatalErr`
|
||||||
|
// You might think that normal compile errors cause the former, and
|
||||||
|
// ICEs cause the latter. But some normal compiler errors also cause
|
||||||
|
// the latter. So we can't meaningfully distinguish them, and group
|
||||||
|
// them together.
|
||||||
|
(Ok(Err(_)), _) | (Err(_), _) => Err(CompilerError::Failed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,8 @@ macro_rules! error {
|
|||||||
/// An error type used to represent an error that has already been reported by the compiler.
|
/// An error type used to represent an error that has already been reported by the compiler.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum CompilerError<T> {
|
pub enum CompilerError<T> {
|
||||||
/// Internal compiler error (I.e.: Compiler crashed).
|
/// Compilation failed, either due to normal errors or ICE.
|
||||||
ICE,
|
Failed,
|
||||||
/// Compilation failed.
|
|
||||||
CompilationFailed,
|
|
||||||
/// Compilation was interrupted.
|
/// Compilation was interrupted.
|
||||||
Interrupted(T),
|
Interrupted(T),
|
||||||
/// Compilation skipped. This happens when users invoke rustc to retrieve information such as
|
/// Compilation skipped. This happens when users invoke rustc to retrieve information such as
|
||||||
@ -54,8 +52,7 @@ where
|
|||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
CompilerError::ICE => write!(f, "Internal Compiler Error"),
|
CompilerError::Failed => write!(f, "Compilation Failed"),
|
||||||
CompilerError::CompilationFailed => write!(f, "Compilation Failed"),
|
|
||||||
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason}"),
|
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason}"),
|
||||||
CompilerError::Skipped => write!(f, "Compilation Skipped"),
|
CompilerError::Skipped => write!(f, "Compilation Skipped"),
|
||||||
}
|
}
|
||||||
@ -68,8 +65,7 @@ where
|
|||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
CompilerError::ICE => write!(f, "Internal Compiler Error"),
|
CompilerError::Failed => write!(f, "Compilation Failed"),
|
||||||
CompilerError::CompilationFailed => write!(f, "Compilation Failed"),
|
|
||||||
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason:?}"),
|
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason:?}"),
|
||||||
CompilerError::Skipped => write!(f, "Compilation Skipped"),
|
CompilerError::Skipped => write!(f, "Compilation Skipped"),
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ fn test_skipped(mut args: Vec<String>) {
|
|||||||
fn test_failed(mut args: Vec<String>) {
|
fn test_failed(mut args: Vec<String>) {
|
||||||
args.push("--cfg=broken".to_string());
|
args.push("--cfg=broken".to_string());
|
||||||
let result = run!(args, || unreachable!() as ControlFlow<()>);
|
let result = run!(args, || unreachable!() as ControlFlow<()>);
|
||||||
assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed));
|
assert_eq!(result, Err(stable_mir::CompilerError::Failed));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test that we are able to pass a closure and set the return according to the captured value.
|
/// Test that we are able to pass a closure and set the return according to the captured value.
|
||||||
|
Loading…
Reference in New Issue
Block a user