Skip to content

Commit f93864c

Browse files
committed
Port check_loans.rs from oldvisit to <V:Visitor> trait API.
1 parent 863aac0 commit f93864c

File tree

1 file changed

+49
-34
lines changed

1 file changed

+49
-34
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use syntax::ast::{m_mutbl, m_imm, m_const};
2727
use syntax::ast;
2828
use syntax::ast_util;
2929
use syntax::codemap::span;
30-
use syntax::oldvisit;
30+
use syntax::visit;
31+
use syntax::visit::Visitor;
3132
use util::ppaux::Repr;
3233

3334
#[deriving(Clone)]
@@ -39,6 +40,27 @@ struct CheckLoanCtxt<'self> {
3940
reported: @mut HashSet<ast::NodeId>,
4041
}
4142

43+
struct CheckLoanVisitor;
44+
45+
impl<'self> Visitor<CheckLoanCtxt<'self>> for CheckLoanVisitor {
46+
fn visit_expr<'a>(&mut self, ex:@ast::expr, e:CheckLoanCtxt<'a>) {
47+
check_loans_in_expr(self, ex, e);
48+
}
49+
fn visit_local(&mut self, l:@ast::Local, e:CheckLoanCtxt) {
50+
check_loans_in_local(self, l, e);
51+
}
52+
fn visit_block(&mut self, b:&ast::Block, e:CheckLoanCtxt) {
53+
check_loans_in_block(self, b, e);
54+
}
55+
fn visit_pat(&mut self, p:@ast::pat, e:CheckLoanCtxt) {
56+
check_loans_in_pat(self, p, e);
57+
}
58+
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&ast::fn_decl,
59+
b:&ast::Block, s:span, n:ast::NodeId, e:CheckLoanCtxt) {
60+
check_loans_in_fn(self, fk, fd, b, s, n, e);
61+
}
62+
}
63+
4264
pub fn check_loans(bccx: @BorrowckCtxt,
4365
dfcx_loans: &LoanDataFlow,
4466
move_data: move_data::FlowedMoveData,
@@ -54,15 +76,8 @@ pub fn check_loans(bccx: @BorrowckCtxt,
5476
reported: @mut HashSet::new(),
5577
};
5678

57-
let vt = oldvisit::mk_vt(@oldvisit::Visitor {
58-
visit_expr: check_loans_in_expr,
59-
visit_local: check_loans_in_local,
60-
visit_block: check_loans_in_block,
61-
visit_pat: check_loans_in_pat,
62-
visit_fn: check_loans_in_fn,
63-
.. *oldvisit::default_visitor()
64-
});
65-
(vt.visit_block)(body, (clcx, vt));
79+
let mut vt = CheckLoanVisitor;
80+
vt.visit_block(body, clcx);
6681
}
6782

6883
enum MoveError {
@@ -626,27 +641,27 @@ impl<'self> CheckLoanCtxt<'self> {
626641
}
627642
}
628643

629-
fn check_loans_in_fn<'a>(fk: &oldvisit::fn_kind,
644+
fn check_loans_in_fn<'a>(visitor: &mut CheckLoanVisitor,
645+
fk: &visit::fn_kind,
630646
decl: &ast::fn_decl,
631647
body: &ast::Block,
632648
sp: span,
633649
id: ast::NodeId,
634-
(this, visitor): (CheckLoanCtxt<'a>,
635-
oldvisit::vt<CheckLoanCtxt<'a>>)) {
650+
this: CheckLoanCtxt<'a>) {
636651
match *fk {
637-
oldvisit::fk_item_fn(*) |
638-
oldvisit::fk_method(*) => {
652+
visit::fk_item_fn(*) |
653+
visit::fk_method(*) => {
639654
// Don't process nested items.
640655
return;
641656
}
642657

643-
oldvisit::fk_anon(*) |
644-
oldvisit::fk_fn_block(*) => {
658+
visit::fk_anon(*) |
659+
visit::fk_fn_block(*) => {
645660
check_captured_variables(this, id, sp);
646661
}
647662
}
648663

649-
oldvisit::visit_fn(fk, decl, body, sp, id, (this, visitor));
664+
visit::walk_fn(visitor, fk, decl, body, sp, id, this);
650665

651666
fn check_captured_variables(this: CheckLoanCtxt,
652667
closure_id: ast::NodeId,
@@ -689,16 +704,16 @@ fn check_loans_in_fn<'a>(fk: &oldvisit::fn_kind,
689704
}
690705
}
691706

692-
fn check_loans_in_local<'a>(local: @ast::Local,
693-
(this, vt): (CheckLoanCtxt<'a>,
694-
oldvisit::vt<CheckLoanCtxt<'a>>)) {
695-
oldvisit::visit_local(local, (this, vt));
707+
fn check_loans_in_local<'a>(vt: &mut CheckLoanVisitor,
708+
local: @ast::Local,
709+
this: CheckLoanCtxt<'a>) {
710+
visit::walk_local(vt, local, this);
696711
}
697712

698-
fn check_loans_in_expr<'a>(expr: @ast::expr,
699-
(this, vt): (CheckLoanCtxt<'a>,
700-
oldvisit::vt<CheckLoanCtxt<'a>>)) {
701-
oldvisit::visit_expr(expr, (this, vt));
713+
fn check_loans_in_expr<'a>(vt: &mut CheckLoanVisitor,
714+
expr: @ast::expr,
715+
this: CheckLoanCtxt<'a>) {
716+
visit::walk_expr(vt, expr, this);
702717

703718
debug!("check_loans_in_expr(expr=%s)",
704719
expr.repr(this.tcx()));
@@ -749,19 +764,19 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
749764
}
750765
}
751766

752-
fn check_loans_in_pat<'a>(pat: @ast::pat,
753-
(this, vt): (CheckLoanCtxt<'a>,
754-
oldvisit::vt<CheckLoanCtxt<'a>>))
767+
fn check_loans_in_pat<'a>(vt: &mut CheckLoanVisitor,
768+
pat: @ast::pat,
769+
this: CheckLoanCtxt<'a>)
755770
{
756771
this.check_for_conflicting_loans(pat.id);
757772
this.check_move_out_from_id(pat.id, pat.span);
758-
oldvisit::visit_pat(pat, (this, vt));
773+
visit::walk_pat(vt, pat, this);
759774
}
760775

761-
fn check_loans_in_block<'a>(blk: &ast::Block,
762-
(this, vt): (CheckLoanCtxt<'a>,
763-
oldvisit::vt<CheckLoanCtxt<'a>>))
776+
fn check_loans_in_block<'a>(vt: &mut CheckLoanVisitor,
777+
blk: &ast::Block,
778+
this: CheckLoanCtxt<'a>)
764779
{
765-
oldvisit::visit_block(blk, (this, vt));
780+
visit::walk_block(vt, blk, this);
766781
this.check_for_conflicting_loans(blk.id);
767782
}

0 commit comments

Comments
 (0)