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 } }