diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 2ceec1b5658..6731ef12306 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -373,11 +373,12 @@ pub(crate) fn cannot_borrow_across_coroutine_yield( span: Span, yield_span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { + let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind; let mut err = struct_span_err!( self, span, E0626, - "borrow may still be in use when coroutine yields", + "borrow may still be in use when {coroutine_kind:#} yields", ); err.span_label(yield_span, "possible yield occurs here"); err diff --git a/tests/ui/coroutine/self_referential_gen_block.rs b/tests/ui/coroutine/self_referential_gen_block.rs index 538d436ed14..14daa2e9c35 100644 --- a/tests/ui/coroutine/self_referential_gen_block.rs +++ b/tests/ui/coroutine/self_referential_gen_block.rs @@ -6,7 +6,7 @@ fn main() { let mut x = { let mut x = gen { let y = 42; - let z = &y; //~ ERROR: borrow may still be in use when coroutine yields + let z = &y; //~ ERROR: borrow may still be in use when `gen` block yields yield 43; panic!("{z}"); }; diff --git a/tests/ui/coroutine/self_referential_gen_block.stderr b/tests/ui/coroutine/self_referential_gen_block.stderr index f9cadf8eb04..586f53df8f2 100644 --- a/tests/ui/coroutine/self_referential_gen_block.stderr +++ b/tests/ui/coroutine/self_referential_gen_block.stderr @@ -1,4 +1,4 @@ -error[E0626]: borrow may still be in use when coroutine yields +error[E0626]: borrow may still be in use when `gen` block yields --> $DIR/self_referential_gen_block.rs:9:21 | LL | let z = &y;