diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 87104364da6af..9ffa3358ac995 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -390,7 +390,9 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(self.tcx).abi(), ty::Closure(..) => ExternAbi::RustCall, + ty::CoroutineClosure(..) => ExternAbi::RustCall, ty::Coroutine(..) => ExternAbi::Rust, + ty::Error(_) => return, _ => bug!("unexpected body ty: {body_ty:?}"), }; diff --git a/tests/ui/async-await/async-closures/instsimplify-nounwind.rs b/tests/ui/async-await/async-closures/instsimplify-nounwind.rs new file mode 100644 index 0000000000000..344e5b367f926 --- /dev/null +++ b/tests/ui/async-await/async-closures/instsimplify-nounwind.rs @@ -0,0 +1,20 @@ +// Regression test for #477: simplify_nounwind_call missing CoroutineClosure arm. +// Before the fix, the MIR instsimplify pass would ICE (bug!("unexpected body ty")) +// when encountering an async closure body type during nounwind simplification. + +//@ edition:2021 +//@ build-pass + +async fn call_once(f: impl std::future::Future) { + f.await; +} + +fn main() { + let _ = async { + let x = 1i32; + let c = async move || { + let _ = x; + }; + call_once(c()).await; + }; +}