Skip to content

Commit

Permalink
Add location to BIR::Loan
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
braw-lee authored and P-E-P committed Aug 1, 2024
1 parent f2c8071 commit bcd860f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class AbstractBuilder
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);
Expand Down Expand Up @@ -600,7 +600,8 @@ class AbstractExprBuilder : public AbstractBuilder,
{
// 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);
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/borrowck/rust-bir-place.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct Loan
{
Mutability mutability;
PlaceId place;
location_t location;
};

/** Allocated places and keeps track of paths. */
Expand Down

0 comments on commit bcd860f

Please sign in to comment.