Skip to content

Commit

Permalink
Use targetted diagnostic for borrow across yield error
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 27, 2023
1 parent 6223744 commit bb90c4b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coroutine/self_referential_gen_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coroutine/self_referential_gen_block.stderr
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit bb90c4b

Please sign in to comment.