Skip to content

Commit d2d8fa2

Browse files
author
Cameron Zwarich
committed
Make analyze_move_out_from use a loop rather than recursion
It will be simpler to make some of the changes that I need to make to analyze_move_out if it uses a loop rather than recursion.
1 parent 3851d68 commit d2d8fa2

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -874,23 +874,30 @@ impl<'a> CheckLoanCtxt<'a> {
874874
// We must check every element of a move path. See
875875
// `borrowck-move-subcomponent.rs` for a test case.
876876

877-
// check for a conflicting loan:
878877
let mut ret = MoveOk;
879-
self.each_in_scope_restriction(expr_id, move_path, |loan, _| {
880-
// Any restriction prevents moves.
881-
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
882-
false
883-
});
878+
let mut loan_path = move_path;
879+
loop {
880+
// check for a conflicting loan:
881+
self.each_in_scope_restriction(expr_id, loan_path, |loan, _| {
882+
// Any restriction prevents moves.
883+
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
884+
false
885+
});
884886

885-
if ret != MoveOk {
886-
return ret
887-
}
887+
if ret != MoveOk {
888+
return ret
889+
}
888890

889-
match *move_path {
890-
LpVar(_) => MoveOk,
891-
LpExtend(ref subpath, _, _) => {
892-
self.analyze_move_out_from(expr_id, &**subpath)
891+
match *loan_path {
892+
LpVar(_) => {
893+
ret = MoveOk;
894+
break;
895+
}
896+
LpExtend(ref lp_base, _, _) => {
897+
loan_path = &**lp_base;
898+
}
893899
}
894900
}
901+
ret
895902
}
896903
}

0 commit comments

Comments
 (0)