Rename analyze_move_out_from to analyze_restrictions_on_use

Also rename MoveError to UseError and MoveOk / MoveWhileBorrowed to
UseOk / UseWhileBorrowed.
This commit is contained in:
Cameron Zwarich 2014-06-13 20:48:09 -07:00
parent 24b1b79cf1
commit 036833ece9

View File

@ -150,9 +150,9 @@ pub fn check_loans(bccx: &BorrowckCtxt,
} }
#[deriving(PartialEq)] #[deriving(PartialEq)]
enum MoveError { enum UseError {
MoveOk, UseOk,
MoveWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span) UseWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span)
} }
impl<'a> CheckLoanCtxt<'a> { impl<'a> CheckLoanCtxt<'a> {
@ -479,9 +479,9 @@ impl<'a> CheckLoanCtxt<'a> {
// We want to detect if there are any loans at all, so we search for // We want to detect if there are any loans at all, so we search for
// any loans incompatible with MutBorrrow, since all other kinds of // any loans incompatible with MutBorrrow, since all other kinds of
// loans are incompatible with that. // loans are incompatible with that.
match self.analyze_move_out_from(id, move_path, ty::MutBorrow) { match self.analyze_restrictions_on_use(id, move_path, ty::MutBorrow) {
MoveOk => { } UseOk => { }
MoveWhileBorrowed(loan_path, loan_span) => { UseWhileBorrowed(loan_path, loan_span) => {
let err_message = match move_kind { let err_message = match move_kind {
move_data::Captured => move_data::Captured =>
format!("cannot move `{}` into closure because it is borrowed", format!("cannot move `{}` into closure because it is borrowed",
@ -866,16 +866,16 @@ impl<'a> CheckLoanCtxt<'a> {
self.bccx.loan_path_to_str(loan_path)).as_slice()); self.bccx.loan_path_to_str(loan_path)).as_slice());
} }
pub fn analyze_move_out_from(&self, pub fn analyze_restrictions_on_use(&self,
expr_id: ast::NodeId, expr_id: ast::NodeId,
move_path: &LoanPath, use_path: &LoanPath,
borrow_kind: ty::BorrowKind) borrow_kind: ty::BorrowKind)
-> MoveError { -> UseError {
debug!("analyze_move_out_from(expr_id={:?}, move_path={})", debug!("analyze_restrictions_on_use(expr_id={:?}, use_path={})",
self.tcx().map.node_to_str(expr_id), self.tcx().map.node_to_str(expr_id),
move_path.repr(self.tcx())); use_path.repr(self.tcx()));
let mut ret = MoveOk; let mut ret = UseOk;
// First, we check for a restriction on the path P being used. This // First, we check for a restriction on the path P being used. This
// accounts for borrows of P but also borrows of subpaths, like P.a.b. // accounts for borrows of P but also borrows of subpaths, like P.a.b.
@ -884,9 +884,9 @@ impl<'a> CheckLoanCtxt<'a> {
// let x = &mut a.b.c; // Restricts a, a.b, and a.b.c // let x = &mut a.b.c; // Restricts a, a.b, and a.b.c
// let y = a; // Conflicts with restriction // let y = a; // Conflicts with restriction
self.each_in_scope_restriction(expr_id, move_path, |loan, _restr| { self.each_in_scope_restriction(expr_id, use_path, |loan, _restr| {
if incompatible(loan.kind, borrow_kind) { if incompatible(loan.kind, borrow_kind) {
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span); ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false false
} else { } else {
true true
@ -905,12 +905,12 @@ impl<'a> CheckLoanCtxt<'a> {
// let x = &mut a.b; // let x = &mut a.b;
// let y = a.c; // let y = a.c;
let mut loan_path = move_path; let mut loan_path = use_path;
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) { incompatible(loan.kind, borrow_kind) {
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span); ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false false
} else { } else {
true true