Skip to content

simplify_nounwind_call missing CoroutineClosure arm causes ICE on async closures #477

@SebTardif

Description

@SebTardif

Bug

simplify_nounwind_call in compiler/rustc_mir_transform/src/instsimplify.rs matches on body_ty.kind() to determine the ABI of a callee, but is missing two arms:

  • ty::CoroutineClosure(..) => ExternAbi::RustCall
  • ty::Error(_) => return

The catch-all _ => bug!("unexpected body ty: {body_ty:?}") causes an ICE when the callee is an async closure body (which desugars to CoroutineClosure), or when the type is an error type from a previous compilation error.

Evidence

Three structurally identical functions in the same crate perform the same type_of(def_id).skip_binder() -> body_ty.kind() dispatch and ALL include the missing arms:

  1. validate.rs (lines 57-62): has ty::CoroutineClosure(..) => ExternAbi::RustCall and ty::Error(_) => return
  2. abort_unwinding_calls.rs (lines 55-59): has both arms
  3. ffi_unwind_calls.rs (lines 30-34): has both arms (Error returns false)

Only instsimplify.rs was missed when CoroutineClosure was added to TyKind.

Impact

ICE (Internal Compiler Error) when async closures are used in certain call patterns that reach the simplify_nounwind_call MIR optimization pass. Async closures have been stable since Rust 1.85. The missing ty::Error arm also causes ICE instead of graceful degradation when compilation already has errors.

PR #481

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mirMIR building and transformsI-crashUnexpected panic or crashP-highHigh impact: affects correctness on common pathsbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions