From 27f72c8887c184ed52f57c09554c43ef424cac49 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Wed, 24 Jun 2026 12:33:17 -0700 Subject: [PATCH] borrowck: treat CoroutineClosure like Closure in mut/move diagnostics Mutability and use-while-moved notes only inspected `ty::Closure`, so async/coroutine closures missed upvar mut suggestions and the closure-origin note suppression. Align with describe_field / moved-or- invoked notes (PR #576 pattern). Signed-off-by: Sebastien Tardif --- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 2 +- .../rustc_borrowck/src/diagnostics/mutability_errors.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index caa566e79e29b..cd5e008dd8c27 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -274,7 +274,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let ty = used_place.ty(self.body, self.infcx.tcx).ty; let needs_note = match ty.kind() { - ty::Closure(id, _) => { + ty::Closure(id, _) | ty::CoroutineClosure(id, _) => { self.infcx.tcx.closure_kind_origin(id.expect_local()).is_none() } _ => true, diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index a4025f28a5511..e2304e3fb5187 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -465,7 +465,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if suggest { self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local); let tcx = self.infcx.tcx; - if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() { + if let ty::Closure(id, _) | ty::CoroutineClosure(id, _) = + *the_place_err.ty(self.body, tcx).ty.kind() + { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); } } @@ -519,7 +521,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let tcx = self.infcx.tcx; if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind() - && let ty::Closure(id, _) = *ty.kind() + && let ty::Closure(id, _) | ty::CoroutineClosure(id, _) = *ty.kind() { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); }