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.
This commit is contained in:
Cameron Zwarich 2014-06-16 15:40:20 -07:00
parent d2ca7465aa
commit 6ca8dbfaed

View File

@ -155,6 +155,12 @@ enum UseError {
UseWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span) UseWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span)
} }
fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
borrow_kind2: ty::BorrowKind)
-> bool {
borrow_kind1 == ty::ImmBorrow && borrow_kind2 == ty::ImmBorrow
}
impl<'a> CheckLoanCtxt<'a> { impl<'a> CheckLoanCtxt<'a> {
pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx } pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx }
@ -542,7 +548,7 @@ impl<'a> CheckLoanCtxt<'a> {
// let y = a; // Conflicts with restriction // let y = a; // Conflicts with restriction
self.each_in_scope_restriction(expr_id, use_path, |loan| { self.each_in_scope_restriction(expr_id, use_path, |loan| {
if incompatible(loan.kind, borrow_kind) { if !compatible_borrow_kinds(loan.kind, borrow_kind) {
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span); ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false false
} else { } else {
@ -566,7 +572,7 @@ impl<'a> CheckLoanCtxt<'a> {
loop { loop {
self.each_in_scope_loan(expr_id, |loan| { self.each_in_scope_loan(expr_id, |loan| {
if *loan.loan_path == *loan_path && if *loan.loan_path == *loan_path &&
incompatible(loan.kind, borrow_kind) { !compatible_borrow_kinds(loan.kind, borrow_kind) {
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span); ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false false
} else { } else {
@ -585,12 +591,6 @@ impl<'a> CheckLoanCtxt<'a> {
} }
return ret; return ret;
fn incompatible(borrow_kind1: ty::BorrowKind,
borrow_kind2: ty::BorrowKind)
-> bool {
borrow_kind1 != ty::ImmBorrow || borrow_kind2 != ty::ImmBorrow
}
} }
fn check_if_path_is_moved(&self, fn check_if_path_is_moved(&self,