Skip to content

Commit 5ccb764

Browse files
author
Cameron Zwarich
committed
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.
1 parent f63fad5 commit 5ccb764

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a> euv::Delegate for GatherLoanCtxt<'a> {
7676

7777
match mode {
7878
euv::Copy => { return; }
79-
euv::Move => { }
79+
euv::Move(_) => { }
8080
}
8181

8282
gather_moves::gather_move_from_expr(
@@ -95,7 +95,7 @@ impl<'a> euv::Delegate for GatherLoanCtxt<'a> {
9595

9696
match mode {
9797
euv::Copy => { return; }
98-
euv::Move => { }
98+
euv::Move(_) => { }
9999
}
100100

101101
gather_moves::gather_move_from_pat(

src/librustc/middle/expr_use_visitor.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ pub enum LoanCause {
8080

8181
#[deriving(PartialEq,Show)]
8282
pub enum ConsumeMode {
83-
Copy, // reference to x where x has a type that copies
84-
Move, // reference to x where x has a type that moves
83+
Copy, // reference to x where x has a type that copies
84+
Move(MoveReason), // reference to x where x has a type that moves
85+
}
86+
87+
#[deriving(PartialEq,Show)]
88+
pub enum MoveReason {
89+
DirectRefMove,
90+
PatBindingMove,
91+
CaptureMove,
8592
}
8693

8794
#[deriving(PartialEq,Show)]
@@ -161,7 +168,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
161168
consume_id: ast::NodeId,
162169
consume_span: Span,
163170
cmt: mc::cmt) {
164-
let mode = copy_or_move(self.tcx(), cmt.ty);
171+
let mode = copy_or_move(self.tcx(), cmt.ty, DirectRefMove);
165172
self.delegate.consume(consume_id, consume_span, cmt, mode);
166173
}
167174

@@ -729,7 +736,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
729736
r, bk, RefBinding);
730737
}
731738
ast::PatIdent(ast::BindByValue(_), _, _) => {
732-
let mode = copy_or_move(typer.tcx(), cmt_pat.ty);
739+
let mode = copy_or_move(typer.tcx(), cmt_pat.ty, PatBindingMove);
733740
delegate.consume_pat(pat, cmt_pat, mode);
734741
}
735742
_ => {
@@ -835,7 +842,8 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
835842
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
836843
closure_expr.span,
837844
freevar.def));
838-
self.delegate_consume(closure_expr.id, freevar.span, cmt_var);
845+
let mode = copy_or_move(self.tcx(), cmt_var.ty, CaptureMove);
846+
self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode);
839847
}
840848
}
841849

@@ -852,7 +860,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
852860
}
853861
}
854862

855-
fn copy_or_move(tcx: &ty::ctxt, ty: ty::t) -> ConsumeMode {
856-
if ty::type_moves_by_default(tcx, ty) { Move } else { Copy }
863+
fn copy_or_move(tcx: &ty::ctxt, ty: ty::t, move_reason: MoveReason) -> ConsumeMode {
864+
if ty::type_moves_by_default(tcx, ty) { Move(move_reason) } else { Copy }
857865
}
858866

0 commit comments

Comments
 (0)