From 92d213f81d9168fe60658ca3eccbe1350fb0b180 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Tue, 23 Jun 2026 22:32:35 -0700 Subject: [PATCH] borrowck: handle CoroutineClosure in describe_field and moved-closure notes Async closures share closure_captures and closure_kind_origin with normal closures. Include CoroutineClosure so borrow diagnostics name captures and moved/invoked-twice notes fire for async closures. Signed-off-by: Sebastien Tardif --- compiler/rustc_borrowck/src/diagnostics/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 56e0c74c85e97..1877d9cd8686a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -279,7 +279,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { }; debug!("add_moved_or_invoked_closure_note: closure={:?}", closure); - if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind() { + if let ty::Closure(did, _) | ty::CoroutineClosure(did, _) = + self.body.local_decls[closure].ty.kind() + { let did = did.expect_local(); if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) { diag.subdiagnostic(OnClosureNote::InvokedTwice { @@ -294,7 +296,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // Check if we are just moving a closure after it has been invoked. if let Some(target) = target - && let ty::Closure(did, _) = self.body.local_decls[target].ty.kind() + && let ty::Closure(did, _) | ty::CoroutineClosure(did, _) = + self.body.local_decls[target].ty.kind() { let did = did.expect_local(); if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) { @@ -526,7 +529,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { ty::Array(ty, _) | ty::Slice(ty) => { self.describe_field_from_ty(ty, field, variant_index, including_tuple_field) } - ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => { + ty::Closure(def_id, _) + | ty::CoroutineClosure(def_id, _) + | ty::Coroutine(def_id, _) => { // We won't be borrowck'ing here if the closure came from another crate, // so it's safe to call `expect_local`. //