diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-08-16 15:06:00 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-08-27 18:47:57 -0700 |
| commit | a20af8b276596c73542fd133d47d1dee8f476588 (patch) | |
| tree | 231521b95ef30d182b5cf6893c5b8f737eaabcb2 | |
| parent | 8693943676487c01fa09f5f3daf0df6a1f71e24d (diff) | |
| download | rust-a20af8b276596c73542fd133d47d1dee8f476588.tar.gz rust-a20af8b276596c73542fd133d47d1dee8f476588.zip | |
librustc: Convert check loans to use the new visitor
| -rw-r--r-- | src/librustc/middle/borrowck/check_loans.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index ba5b9d9dca1..3ed5e886414 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -27,8 +27,8 @@ use syntax::ast::m_mutbl; use syntax::ast; use syntax::ast_util; use syntax::codemap::span; -use syntax::visit; use syntax::visit::Visitor; +use syntax::visit; use util::ppaux::Repr; #[deriving(Clone)] @@ -68,7 +68,7 @@ pub fn check_loans(bccx: @BorrowckCtxt, body: &ast::Block) { debug!("check_loans(body id=%?)", body.id); - let clcx = CheckLoanCtxt { + let mut clcx = CheckLoanCtxt { bccx: bccx, dfcx_loans: dfcx_loans, move_data: @move_data, @@ -86,6 +86,44 @@ enum MoveError { } impl<'self> CheckLoanCtxt<'self> { + fn check_by_move_capture(&self, + closure_id: ast::NodeId, + cap_var: &moves::CaptureVar, + move_path: @LoanPath) { + let move_err = self.analyze_move_out_from(closure_id, move_path); + match move_err { + MoveOk => {} + MoveWhileBorrowed(loan_path, loan_span) => { + self.bccx.span_err( + cap_var.span, + fmt!("cannot move `%s` into closure \ + because it is borrowed", + self.bccx.loan_path_to_str(move_path))); + self.bccx.span_note( + loan_span, + fmt!("borrow of `%s` occurs here", + self.bccx.loan_path_to_str(loan_path))); + } + } + } + + fn check_captured_variables(&self, closure_id: ast::NodeId, span: span) { + let cap_vars = self.bccx.capture_map.get(&closure_id); + for cap_var in cap_vars.iter() { + let var_id = ast_util::def_id_of_def(cap_var.def).node; + let var_path = @LpVar(var_id); + self.check_if_path_is_moved(closure_id, span, + MovedInCapture, var_path); + match cap_var.mode { + moves::CapRef | moves::CapCopy => {} + moves::CapMove => { + self.check_by_move_capture(closure_id, cap_var, var_path); + } + } + } + return; + } + pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx } pub fn each_issued_loan(&self, @@ -827,3 +865,4 @@ fn check_loans_in_block<'a>(vt: &mut CheckLoanVisitor, visit::walk_block(vt, blk, this); this.check_for_conflicting_loans(blk.id); } + |
