about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@mozilla.com>2014-06-13 20:48:09 -0700
committerCameron Zwarich <zwarich@mozilla.com>2014-06-13 20:48:09 -0700
commitd2d8fa2a0980fc6bf1a842cfff7d77ae9b95185f (patch)
tree0e204ccb4314e65c2b7060c85e0072fc3e950501 /src
parent3851d68a27d41dfd15e12a75b590f362a0675870 (diff)
downloadrust-d2d8fa2a0980fc6bf1a842cfff7d77ae9b95185f.tar.gz
rust-d2d8fa2a0980fc6bf1a842cfff7d77ae9b95185f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/borrowck/check_loans.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs
index ece8d973236..8ec93bb51b6 100644
--- a/src/librustc/middle/borrowck/check_loans.rs
+++ b/src/librustc/middle/borrowck/check_loans.rs
@@ -874,23 +874,30 @@ impl<'a> CheckLoanCtxt<'a> {
         // We must check every element of a move path. See
         // `borrowck-move-subcomponent.rs` for a test case.
 
-        // check for a conflicting loan:
         let mut ret = MoveOk;
-        self.each_in_scope_restriction(expr_id, move_path, |loan, _| {
-            // Any restriction prevents moves.
-            ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
-            false
-        });
+        let mut loan_path = move_path;
+        loop {
+            // check for a conflicting loan:
+            self.each_in_scope_restriction(expr_id, loan_path, |loan, _| {
+                // Any restriction prevents moves.
+                ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
+                false
+            });
 
-        if ret != MoveOk {
-            return ret
-        }
+            if ret != MoveOk {
+                return ret
+            }
 
-        match *move_path {
-            LpVar(_) => MoveOk,
-            LpExtend(ref subpath, _, _) => {
-                self.analyze_move_out_from(expr_id, &**subpath)
+            match *loan_path {
+                LpVar(_) => {
+                    ret = MoveOk;
+                    break;
+                }
+                LpExtend(ref lp_base, _, _) => {
+                    loan_path = &**lp_base;
+                }
             }
         }
+        ret
     }
 }