Skip to content

Commit ef854c9

Browse files
committed
Switch main borrowck to <V:Visitor> trait API.
fix borrowck/mod.rs to deal with fn_kind enum fallout.
1 parent 0d85928 commit ef854c9

File tree

1 file changed

+22
-12
lines changed
  • src/librustc/middle/borrowck

1 file changed

+22
-12
lines changed

src/librustc/middle/borrowck/mod.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ use std::ops::{BitOr, BitAnd};
2626
use std::result::{Result};
2727
use syntax::ast;
2828
use syntax::ast_map;
29-
use syntax::oldvisit;
3029
use syntax::codemap::span;
3130
use syntax::parse::token;
31+
use syntax::visit;
32+
use syntax::visit::{Visitor,fn_kind};
33+
use syntax::ast::{fn_decl,Block,NodeId};
3234

3335
macro_rules! if_ok(
3436
($inp: expr) => (
@@ -59,6 +61,15 @@ impl Clone for LoanDataFlowOperator {
5961

6062
pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;
6163

64+
struct BorrowckVisitor;
65+
66+
impl Visitor<@BorrowckCtxt> for BorrowckVisitor {
67+
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl,
68+
b:&Block, s:span, n:NodeId, e:@BorrowckCtxt) {
69+
borrowck_fn(self, fk, fd, b, s, n, e);
70+
}
71+
}
72+
6273
pub fn check_crate(
6374
tcx: ty::ctxt,
6475
method_map: typeck::method_map,
@@ -86,9 +97,8 @@ pub fn check_crate(
8697
}
8798
};
8899

89-
let v = oldvisit::mk_vt(@oldvisit::Visitor {visit_fn: borrowck_fn,
90-
..*oldvisit::default_visitor()});
91-
oldvisit::visit_crate(crate, (bccx, v));
100+
let mut v = BorrowckVisitor;
101+
visit::walk_crate(&mut v, crate, bccx);
92102

93103
if tcx.sess.borrowck_stats() {
94104
io::println("--- borrowck stats ---");
@@ -113,21 +123,21 @@ pub fn check_crate(
113123
}
114124
}
115125

116-
fn borrowck_fn(fk: &oldvisit::fn_kind,
126+
fn borrowck_fn(v: &mut BorrowckVisitor,
127+
fk: &visit::fn_kind,
117128
decl: &ast::fn_decl,
118129
body: &ast::Block,
119130
sp: span,
120131
id: ast::NodeId,
121-
(this, v): (@BorrowckCtxt,
122-
oldvisit::vt<@BorrowckCtxt>)) {
132+
this: @BorrowckCtxt) {
123133
match fk {
124-
&oldvisit::fk_anon(*) |
125-
&oldvisit::fk_fn_block(*) => {
134+
&visit::fk_anon(*) |
135+
&visit::fk_fn_block(*) => {
126136
// Closures are checked as part of their containing fn item.
127137
}
128138

129-
&oldvisit::fk_item_fn(*) |
130-
&oldvisit::fk_method(*) => {
139+
&visit::fk_item_fn(*) |
140+
&visit::fk_method(*) => {
131141
debug!("borrowck_fn(id=%?)", id);
132142

133143
// Check the body of fn items.
@@ -156,7 +166,7 @@ fn borrowck_fn(fk: &oldvisit::fn_kind,
156166
}
157167
}
158168

159-
oldvisit::visit_fn(fk, decl, body, sp, id, (this, v));
169+
visit::walk_fn(v, fk, decl, body, sp, id, this);
160170
}
161171

162172
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)