提交 5ccb7644 编写于 作者: C Cameron Zwarich

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.
上级 f63fad5d
......@@ -76,7 +76,7 @@ fn consume(&mut self,
match mode {
euv::Copy => { return; }
euv::Move => { }
euv::Move(_) => { }
}
gather_moves::gather_move_from_expr(
......@@ -95,7 +95,7 @@ fn consume_pat(&mut self,
match mode {
euv::Copy => { return; }
euv::Move => { }
euv::Move(_) => { }
}
gather_moves::gather_move_from_pat(
......
......@@ -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 @@ fn delegate_consume(&mut self,
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 @@ fn walk_pat(&mut self, cmt_discr: mc::cmt, pat: @ast::Pat) {
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 @@ fn walk_by_value_captures(&mut self,
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 @@ fn cat_captured_var(&mut self,
}
}
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 }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册