From 9ab8fb00e90a1b44fc87c26d181176667b5faac7 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Wed, 24 Jun 2026 12:33:19 -0700 Subject: [PATCH] borrowck: detect FnMut for CoroutineClosure in region error helpers `is_closure_fn_mut` only considered `DefiningTy::Closure`, so region diagnostics for async/coroutine closures never treated `ClosureEnv` as `FnMut` even when the coroutine-closure kind was `FnMut`. Include `DefiningTy::CoroutineClosure` via `as_coroutine_closure().kind()`. Signed-off-by: Sebastien Tardif --- .../rustc_borrowck/src/diagnostics/region_errors.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index e436d95cdb087..29363da0ceb10 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -179,9 +179,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let Some(r) = self.to_error_region(fr) && let ty::ReLateParam(late_param) = r.kind() && let ty::LateParamRegionKind::ClosureEnv = late_param.kind - && let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty { - return args.as_closure().kind() == ty::ClosureKind::FnMut; + return match self.regioncx.universal_regions().defining_ty { + DefiningTy::Closure(_, args) => args.as_closure().kind() == ty::ClosureKind::FnMut, + // Async/coroutine closures use the same `ClosureEnv` late-param region shape. + DefiningTy::CoroutineClosure(_, args) => { + args.as_coroutine_closure().kind() == ty::ClosureKind::FnMut + } + _ => false, + }; } false