Skip to content

Commit 6ca8dbf

Browse files
author
Cameron Zwarich
committed
Make a new compatible_borrow_kinds helper function
Move the `incompatible` helper function from analyze_restrictions_on_use to the file scope and invert its meaning to account for future uses.
1 parent d2ca746 commit 6ca8dbf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ enum UseError {
155155
UseWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span)
156156
}
157157

158+
fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
159+
borrow_kind2: ty::BorrowKind)
160+
-> bool {
161+
borrow_kind1 == ty::ImmBorrow && borrow_kind2 == ty::ImmBorrow
162+
}
163+
158164
impl<'a> CheckLoanCtxt<'a> {
159165
pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx }
160166

@@ -542,7 +548,7 @@ impl<'a> CheckLoanCtxt<'a> {
542548
// let y = a; // Conflicts with restriction
543549

544550
self.each_in_scope_restriction(expr_id, use_path, |loan| {
545-
if incompatible(loan.kind, borrow_kind) {
551+
if !compatible_borrow_kinds(loan.kind, borrow_kind) {
546552
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
547553
false
548554
} else {
@@ -566,7 +572,7 @@ impl<'a> CheckLoanCtxt<'a> {
566572
loop {
567573
self.each_in_scope_loan(expr_id, |loan| {
568574
if *loan.loan_path == *loan_path &&
569-
incompatible(loan.kind, borrow_kind) {
575+
!compatible_borrow_kinds(loan.kind, borrow_kind) {
570576
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
571577
false
572578
} else {
@@ -585,12 +591,6 @@ impl<'a> CheckLoanCtxt<'a> {
585591
}
586592

587593
return ret;
588-
589-
fn incompatible(borrow_kind1: ty::BorrowKind,
590-
borrow_kind2: ty::BorrowKind)
591-
-> bool {
592-
borrow_kind1 != ty::ImmBorrow || borrow_kind2 != ty::ImmBorrow
593-
}
594594
}
595595

596596
fn check_if_path_is_moved(&self,

0 commit comments

Comments
 (0)