Skip to content

Commit 7211a5b

Browse files
committed
librustc: Convert check loans to use the new visitor
1 parent e8014bb commit 7211a5b

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use syntax::ast::m_mutbl;
2727
use syntax::ast;
2828
use syntax::ast_util;
2929
use syntax::codemap::span;
30-
use syntax::visit;
3130
use syntax::visit::Visitor;
31+
use syntax::visit;
3232
use util::ppaux::Repr;
3333

3434
#[deriving(Clone)]
@@ -68,7 +68,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
6868
body: &ast::Block) {
6969
debug!("check_loans(body id=%?)", body.id);
7070

71-
let clcx = CheckLoanCtxt {
71+
let mut clcx = CheckLoanCtxt {
7272
bccx: bccx,
7373
dfcx_loans: dfcx_loans,
7474
move_data: @move_data,
@@ -86,6 +86,44 @@ enum MoveError {
8686
}
8787

8888
impl<'self> CheckLoanCtxt<'self> {
89+
fn check_by_move_capture(&self,
90+
closure_id: ast::NodeId,
91+
cap_var: &moves::CaptureVar,
92+
move_path: @LoanPath) {
93+
let move_err = self.analyze_move_out_from(closure_id, move_path);
94+
match move_err {
95+
MoveOk => {}
96+
MoveWhileBorrowed(loan_path, loan_span) => {
97+
self.bccx.span_err(
98+
cap_var.span,
99+
fmt!("cannot move `%s` into closure \
100+
because it is borrowed",
101+
self.bccx.loan_path_to_str(move_path)));
102+
self.bccx.span_note(
103+
loan_span,
104+
fmt!("borrow of `%s` occurs here",
105+
self.bccx.loan_path_to_str(loan_path)));
106+
}
107+
}
108+
}
109+
110+
fn check_captured_variables(&self, closure_id: ast::NodeId, span: span) {
111+
let cap_vars = self.bccx.capture_map.get(&closure_id);
112+
for cap_var in cap_vars.iter() {
113+
let var_id = ast_util::def_id_of_def(cap_var.def).node;
114+
let var_path = @LpVar(var_id);
115+
self.check_if_path_is_moved(closure_id, span,
116+
MovedInCapture, var_path);
117+
match cap_var.mode {
118+
moves::CapRef | moves::CapCopy => {}
119+
moves::CapMove => {
120+
self.check_by_move_capture(closure_id, cap_var, var_path);
121+
}
122+
}
123+
}
124+
return;
125+
}
126+
89127
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
90128

91129
pub fn each_issued_loan(&self,
@@ -782,3 +820,4 @@ fn check_loans_in_block<'a>(vt: &mut CheckLoanVisitor,
782820
visit::walk_block(vt, blk, this);
783821
this.check_for_conflicting_loans(blk.id);
784822
}
823+

0 commit comments

Comments
 (0)