Use targetted diagnostic for borrow across yield error

This commit is contained in:
Oli Scherer 2023-10-24 10:12:49 +00:00
parent 6223744078
commit bb90c4bf35
3 changed files with 4 additions and 3 deletions

View File

@ -373,11 +373,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
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

View File

@ -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}");
};

View File

@ -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;