From ec741c43509a4f978efacfd653db298911cfbcef Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Tue, 23 Jun 2026 22:23:58 -0700 Subject: [PATCH] diag: handle CoroutineClosure in fulfillment span and borrow explain - adjust_fulfillment_errors: include CoroutineClosure with Closure/Coroutine when attributing trait ref self_ty spans to the def - explain_borrow: describe drop as async closure for CoroutineClosure Signed-off-by: Sebastien Tardif --- compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs | 1 + .../src/fn_ctxt/adjust_fulfillment_errors.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 5d154cc7b9050..47fcdd390e0ee 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -211,6 +211,7 @@ impl<'tcx> BorrowExplanation<'tcx> { // Otherwise, just report the whole type (and use // the intentionally fuzzy phrase "destructor") ty::Closure(..) => ("destructor", "closure".to_owned()), + ty::CoroutineClosure(..) => ("destructor", "async closure".to_owned()), ty::Coroutine(..) => ("destructor", "coroutine".to_owned()), _ => ("destructor", format!("type `{}`", local_decl.ty)), diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 825aa37065e15..c76a347af03a2 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -486,8 +486,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let traits::FulfillmentErrorCode::Select(traits::SelectionError::SignatureMismatch( traits::SignatureMismatchData { expected_trait_ref, .. }, )) = error.code - && let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) = - expected_trait_ref.self_ty().kind() + && let ty::Closure(def_id, _) + | ty::CoroutineClosure(def_id, _) + | ty::Coroutine(def_id, ..) = expected_trait_ref.self_ty().kind() && span.overlaps(self.tcx.def_span(*def_id)) { true