about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@mozilla.com>2014-06-06 11:59:33 -0700
committerCameron Zwarich <zwarich@mozilla.com>2014-06-06 11:59:33 -0700
commit5ccb7644be0f0ab04a76bf88c93cecb63b1ba20d (patch)
tree637304235d1e437d28e5dcea2a01fcdb438213b4
parentf63fad5d60f451013a6787fec4db12b77cab018c (diff)
downloadrust-5ccb7644be0f0ab04a76bf88c93cecb63b1ba20d.tar.gz
rust-5ccb7644be0f0ab04a76bf88c93cecb63b1ba20d.zip
Add a move reason to the Move ConsumeMode.
Currently it is not possible to distinguish moves caused by captures
in the ExprUseVisitor interface. Since check_Loans needs to make that
distinction for generating good diagnostics, this is necessary for
check_loans to switch to ExprUseVisitor.
-rw-r--r--src/librustc/middle/borrowck/gather_loans/mod.rs4
-rw-r--r--src/librustc/middle/expr_use_visitor.rs22
2 files changed, 17 insertions, 9 deletions
diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs
index d34ce7f6a5f..5192ddc793b 100644
--- a/src/librustc/middle/borrowck/gather_loans/mod.rs
+++ b/src/librustc/middle/borrowck/gather_loans/mod.rs
@@ -76,7 +76,7 @@ impl<'a> euv::Delegate for GatherLoanCtxt<'a> {
 
         match mode {
             euv::Copy => { return; }
-            euv::Move => { }
+            euv::Move(_) => { }
         }
 
         gather_moves::gather_move_from_expr(
@@ -95,7 +95,7 @@ impl<'a> euv::Delegate for GatherLoanCtxt<'a> {
 
         match mode {
             euv::Copy => { return; }
-            euv::Move => { }
+            euv::Move(_) => { }
         }
 
         gather_moves::gather_move_from_pat(
diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs
index f806fcb1f7e..cd71d95bee9 100644
--- a/src/librustc/middle/expr_use_visitor.rs
+++ b/src/librustc/middle/expr_use_visitor.rs
@@ -80,8 +80,15 @@ pub enum LoanCause {
 
 #[deriving(PartialEq,Show)]
 pub enum ConsumeMode {
-    Copy,    // reference to x where x has a type that copies
-    Move,    // reference to x where x has a type that moves
+    Copy,                // reference to x where x has a type that copies
+    Move(MoveReason),    // reference to x where x has a type that moves
+}
+
+#[deriving(PartialEq,Show)]
+pub enum MoveReason {
+    DirectRefMove,
+    PatBindingMove,
+    CaptureMove,
 }
 
 #[deriving(PartialEq,Show)]
@@ -161,7 +168,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
                         consume_id: ast::NodeId,
                         consume_span: Span,
                         cmt: mc::cmt) {
-        let mode = copy_or_move(self.tcx(), cmt.ty);
+        let mode = copy_or_move(self.tcx(), cmt.ty, DirectRefMove);
         self.delegate.consume(consume_id, consume_span, cmt, mode);
     }
 
@@ -729,7 +736,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
                                              r, bk, RefBinding);
                     }
                     ast::PatIdent(ast::BindByValue(_), _, _) => {
-                        let mode = copy_or_move(typer.tcx(), cmt_pat.ty);
+                        let mode = copy_or_move(typer.tcx(), cmt_pat.ty, PatBindingMove);
                         delegate.consume_pat(pat, cmt_pat, mode);
                     }
                     _ => {
@@ -835,7 +842,8 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
             let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
                                                                closure_expr.span,
                                                                freevar.def));
-            self.delegate_consume(closure_expr.id, freevar.span, cmt_var);
+            let mode = copy_or_move(self.tcx(), cmt_var.ty, CaptureMove);
+            self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode);
         }
     }
 
@@ -852,7 +860,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
     }
 }
 
-fn copy_or_move(tcx: &ty::ctxt, ty: ty::t) -> ConsumeMode {
-    if ty::type_moves_by_default(tcx, ty) { Move } else { Copy }
+fn copy_or_move(tcx: &ty::ctxt, ty: ty::t, move_reason: MoveReason) -> ConsumeMode {
+    if ty::type_moves_by_default(tcx, ty) { Move(move_reason) } else { Copy }
 }