Skip to content

Commit 0d85928

Browse files
committed
Switch borrowck::gather_loans to <V:Visitor> visit API.
Placate make tidy. Remove unnecessary references to oldvisit.
1 parent a5a5432 commit 0d85928

File tree

1 file changed

+65
-45
lines changed
  • src/librustc/middle/borrowck/gather_loans

1 file changed

+65
-45
lines changed

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

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ use syntax::ast;
3131
use syntax::ast_util::id_range;
3232
use syntax::codemap::span;
3333
use syntax::print::pprust;
34-
use syntax::oldvisit;
34+
use syntax::visit;
35+
use syntax::visit::Visitor;
36+
use syntax::ast::{expr, fn_kind, fn_decl, Block, NodeId, stmt, pat, Local};
3537

3638
mod lifetime;
3739
mod restrictions;
@@ -72,6 +74,30 @@ struct GatherLoanCtxt {
7274
repeating_ids: ~[ast::NodeId]
7375
}
7476

77+
struct GatherLoanVisitor;
78+
79+
impl visit::Visitor<@mut GatherLoanCtxt> for GatherLoanVisitor {
80+
fn visit_expr(&mut self, ex:@expr, e:@mut GatherLoanCtxt) {
81+
gather_loans_in_expr(self, ex, e);
82+
}
83+
fn visit_block(&mut self, b:&Block, e:@mut GatherLoanCtxt) {
84+
gather_loans_in_block(self, b, e);
85+
}
86+
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl, b:&Block,
87+
s:span, n:NodeId, e:@mut GatherLoanCtxt) {
88+
gather_loans_in_fn(self, fk, fd, b, s, n, e);
89+
}
90+
fn visit_stmt(&mut self, s:@stmt, e:@mut GatherLoanCtxt) {
91+
add_stmt_to_map(self, s, e);
92+
}
93+
fn visit_pat(&mut self, p:@pat, e:@mut GatherLoanCtxt) {
94+
add_pat_to_id_range(self, p, e);
95+
}
96+
fn visit_local(&mut self, l:@Local, e:@mut GatherLoanCtxt) {
97+
gather_loans_in_local(self, l, e);
98+
}
99+
}
100+
75101
pub fn gather_loans(bccx: @BorrowckCtxt,
76102
decl: &ast::fn_decl,
77103
body: &ast::Block)
@@ -85,64 +111,57 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
85111
move_data: @mut MoveData::new()
86112
};
87113
glcx.gather_fn_arg_patterns(decl, body);
88-
let v = oldvisit::mk_vt(@oldvisit::Visitor {
89-
visit_expr: gather_loans_in_expr,
90-
visit_block: gather_loans_in_block,
91-
visit_fn: gather_loans_in_fn,
92-
visit_stmt: add_stmt_to_map,
93-
visit_pat: add_pat_to_id_range,
94-
visit_local: gather_loans_in_local,
95-
.. *oldvisit::default_visitor()
96-
});
97-
(v.visit_block)(body, (glcx, v));
114+
115+
let mut v = GatherLoanVisitor;
116+
v.visit_block(body, glcx);
98117
return (glcx.id_range, glcx.all_loans, glcx.move_data);
99118
}
100119

101-
fn add_pat_to_id_range(p: @ast::pat,
102-
(this, v): (@mut GatherLoanCtxt,
103-
oldvisit::vt<@mut GatherLoanCtxt>)) {
120+
fn add_pat_to_id_range(v: &mut GatherLoanVisitor,
121+
p: @ast::pat,
122+
this: @mut GatherLoanCtxt) {
104123
// NB: This visitor function just adds the pat ids into the id
105124
// range. We gather loans that occur in patterns using the
106125
// `gather_pat()` method below. Eventually these two should be
107126
// brought together.
108127
this.id_range.add(p.id);
109-
oldvisit::visit_pat(p, (this, v));
128+
visit::walk_pat(v, p, this);
110129
}
111130

112-
fn gather_loans_in_fn(fk: &oldvisit::fn_kind,
131+
fn gather_loans_in_fn(v: &mut GatherLoanVisitor,
132+
fk: &fn_kind,
113133
decl: &ast::fn_decl,
114134
body: &ast::Block,
115135
sp: span,
116136
id: ast::NodeId,
117-
(this, v): (@mut GatherLoanCtxt,
118-
oldvisit::vt<@mut GatherLoanCtxt>)) {
137+
this: @mut GatherLoanCtxt) {
119138
match fk {
120139
// Do not visit items here, the outer loop in borrowck/mod
121140
// will visit them for us in turn.
122-
&oldvisit::fk_item_fn(*) | &oldvisit::fk_method(*) => {
141+
&visit::fk_item_fn(*) | &visit::fk_method(*) => {
123142
return;
124143
}
125144

126145
// Visit closures as part of the containing item.
127-
&oldvisit::fk_anon(*) | &oldvisit::fk_fn_block(*) => {
146+
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
128147
this.push_repeating_id(body.id);
129-
oldvisit::visit_fn(fk, decl, body, sp, id, (this, v));
148+
visit::walk_fn(v, fk, decl, body, sp, id, this);
130149
this.pop_repeating_id(body.id);
131150
this.gather_fn_arg_patterns(decl, body);
132151
}
133152
}
134153
}
135154

136-
fn gather_loans_in_block(blk: &ast::Block,
137-
(this, vt): (@mut GatherLoanCtxt,
138-
oldvisit::vt<@mut GatherLoanCtxt>)) {
155+
fn gather_loans_in_block(v: &mut GatherLoanVisitor,
156+
blk: &ast::Block,
157+
this: @mut GatherLoanCtxt) {
139158
this.id_range.add(blk.id);
140-
oldvisit::visit_block(blk, (this, vt));
159+
visit::walk_block(v, blk, this);
141160
}
142161

143-
fn gather_loans_in_local(local: @ast::Local,
144-
(this, vt): (@mut GatherLoanCtxt,
145-
oldvisit::vt<@mut GatherLoanCtxt>)) {
162+
fn gather_loans_in_local(v: &mut GatherLoanVisitor,
163+
local: @ast::Local,
164+
this: @mut GatherLoanCtxt) {
146165
match local.init {
147166
None => {
148167
// Variable declarations without initializers are considered "moves":
@@ -173,12 +192,13 @@ fn gather_loans_in_local(local: @ast::Local,
173192
}
174193
}
175194

176-
oldvisit::visit_local(local, (this, vt));
195+
visit::walk_local(v, local, this);
177196
}
178197

179-
fn gather_loans_in_expr(ex: @ast::expr,
180-
(this, vt): (@mut GatherLoanCtxt,
181-
oldvisit::vt<@mut GatherLoanCtxt>)) {
198+
199+
fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
200+
ex: @ast::expr,
201+
this: @mut GatherLoanCtxt) {
182202
let bccx = this.bccx;
183203
let tcx = bccx.tcx;
184204

@@ -218,7 +238,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
218238
// for the lifetime `scope_r` of the resulting ptr:
219239
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
220240
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
221-
oldvisit::visit_expr(ex, (this, vt));
241+
visit::walk_expr(v, ex, this);
222242
}
223243

224244
ast::expr_assign(l, _) | ast::expr_assign_op(_, _, l, _) => {
@@ -235,7 +255,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
235255
// with moves etc, just ignore.
236256
}
237257
}
238-
oldvisit::visit_expr(ex, (this, vt));
258+
visit::walk_expr(v, ex, this);
239259
}
240260

241261
ast::expr_match(ex_v, ref arms) => {
@@ -245,7 +265,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
245265
this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
246266
}
247267
}
248-
oldvisit::visit_expr(ex, (this, vt));
268+
visit::walk_expr(v, ex, this);
249269
}
250270

251271
ast::expr_index(_, _, arg) |
@@ -259,36 +279,36 @@ fn gather_loans_in_expr(ex: @ast::expr,
259279
let scope_r = ty::re_scope(ex.id);
260280
let arg_cmt = this.bccx.cat_expr(arg);
261281
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
262-
oldvisit::visit_expr(ex, (this, vt));
282+
visit::walk_expr(v, ex, this);
263283
}
264284

265285
// see explanation attached to the `root_ub` field:
266286
ast::expr_while(cond, ref body) => {
267287
// during the condition, can only root for the condition
268288
this.push_repeating_id(cond.id);
269-
(vt.visit_expr)(cond, (this, vt));
289+
v.visit_expr(cond, this);
270290
this.pop_repeating_id(cond.id);
271291

272292
// during body, can only root for the body
273293
this.push_repeating_id(body.id);
274-
(vt.visit_block)(body, (this, vt));
294+
v.visit_block(body, this);
275295
this.pop_repeating_id(body.id);
276296
}
277297

278298
// see explanation attached to the `root_ub` field:
279299
ast::expr_loop(ref body, _) => {
280300
this.push_repeating_id(body.id);
281-
oldvisit::visit_expr(ex, (this, vt));
301+
visit::walk_expr(v, ex, this);
282302
this.pop_repeating_id(body.id);
283303
}
284304

285305
ast::expr_fn_block(*) => {
286306
gather_moves::gather_captures(this.bccx, this.move_data, ex);
287-
oldvisit::visit_expr(ex, (this, vt));
307+
visit::walk_expr(v, ex, this);
288308
}
289309

290310
_ => {
291-
oldvisit::visit_expr(ex, (this, vt));
311+
visit::walk_expr(v, ex, this);
292312
}
293313
}
294314
}
@@ -770,14 +790,14 @@ impl GatherLoanCtxt {
770790

771791
// Setting up info that preserve needs.
772792
// This is just the most convenient place to do it.
773-
fn add_stmt_to_map(stmt: @ast::stmt,
774-
(this, vt): (@mut GatherLoanCtxt,
775-
oldvisit::vt<@mut GatherLoanCtxt>)) {
793+
fn add_stmt_to_map(v: &mut GatherLoanVisitor,
794+
stmt: @ast::stmt,
795+
this: @mut GatherLoanCtxt) {
776796
match stmt.node {
777797
ast::stmt_expr(_, id) | ast::stmt_semi(_, id) => {
778798
this.bccx.stmt_map.insert(id);
779799
}
780800
_ => ()
781801
}
782-
oldvisit::visit_stmt(stmt, (this, vt));
802+
visit::walk_stmt(v, stmt, this);
783803
}

0 commit comments

Comments
 (0)