]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add location to BIR::Loan
authorKushal Pal <kushalpal109@gmail.com>
Tue, 9 Jul 2024 10:37:27 +0000 (10:37 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:02 +0000 (15:32 +0100)
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 46f811ea25a7fc4cc8f3d4703ffc9f2f172481cf..16fcb6abca73169f09f735234ce88b808eecb599 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 8c38e8ed3cd812207d583c8d36ccd8b909d5ba70..66da3dab380c9da6ff6c66c48697485ace3a9eae 100644 (file)
@@ -162,6 +162,7 @@ struct Loan
 {
   Mutability mutability;
   PlaceId place;
+  location_t location;
 };
 
 /** Allocated places and keeps track of paths. */