Skip to content

Commit bb90c4b

Browse files
committed
Use targetted diagnostic for borrow across yield error
1 parent 6223744 commit bb90c4b

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
373373
span: Span,
374374
yield_span: Span,
375375
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
376+
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
376377
let mut err = struct_span_err!(
377378
self,
378379
span,
379380
E0626,
380-
"borrow may still be in use when coroutine yields",
381+
"borrow may still be in use when {coroutine_kind:#} yields",
381382
);
382383
err.span_label(yield_span, "possible yield occurs here");
383384
err

tests/ui/coroutine/self_referential_gen_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
let mut x = {
77
let mut x = gen {
88
let y = 42;
9-
let z = &y; //~ ERROR: borrow may still be in use when coroutine yields
9+
let z = &y; //~ ERROR: borrow may still be in use when `gen` block yields
1010
yield 43;
1111
panic!("{z}");
1212
};

tests/ui/coroutine/self_referential_gen_block.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0626]: borrow may still be in use when coroutine yields
1+
error[E0626]: borrow may still be in use when `gen` block yields
22
--> $DIR/self_referential_gen_block.rs:9:21
33
|
44
LL | let z = &y;

0 commit comments

Comments
 (0)