]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add location to BIR::Loan
authorKushal Pal <kushalpal109@gmail.com>
Tue, 9 Jul 2024 10:37:27 +0000 (10:37 +0000)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Thu, 1 Aug 2024 10:38:50 +0000 (10:38 +0000)
This commit adds location_t to BIR::Loan, this location will point to
location is source code where the borrow occured, this information will
be useful for reporting borrow-checking errors.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h:
Fill location for loan.
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Add location field.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
gcc/rust/checks/errors/borrowck/rust-bir-place.h

index 877c34ba450a36d533607b8152d03542a9f4b0ca..e542c4ebb18dc4e3516efcb0d99472d1f9bd365b 100644 (file)
@@ -307,7 +307,7 @@ protected: // Helpers to add BIR statements
                        location_t location)
   {
     auto mutability = ty->as<const TyTy::ReferenceType> ()->mutability ();
-    auto loan = ctx.place_db.add_loan ({mutability, place_id});
+    auto loan = ctx.place_db.add_loan ({mutability, place_id, location});
     push_tmp_assignment (new BorrowExpr (place_id, loan,
                                         ctx.place_db.get_next_free_region ()),
                         ty, location);
@@ -600,7 +600,8 @@ protected:
   {
     // TODO: deduplicate with borrow_place
     auto loan = ctx.place_db.add_loan (
-      {ty->as<const TyTy::ReferenceType> ()->mutability (), place_id});
+      {ty->as<const TyTy::ReferenceType> ()->mutability (), place_id,
+       location});
     return_expr (new BorrowExpr (place_id, loan,
                                 ctx.place_db.get_next_free_region ()),
                 ty, location);
index 752c8f42c0075c983c7d99d061b98256deb6ea81..06faa77a6fa0a8dd9ef16602d537917b2a2d33d8 100644 (file)
@@ -162,6 +162,7 @@ struct Loan
 {
   Mutability mutability;
   PlaceId place;
+  location_t location;
 };
 
 /** Allocated places and keeps track of paths. */