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.
This commit is contained in:
Cameron Zwarich 2014-06-06 11:59:33 -07:00
parent f63fad5d60
commit 5ccb7644be
2 changed files with 17 additions and 9 deletions

View file

@ -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(

View file

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