Skip to content

Commit 5c802a6

Browse files
committed
Port kind.rs from oldvisit to <V:Visitor> trait API.
1 parent 35b1fc5 commit 5c802a6

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

src/librustc/middle/kind.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use syntax::attr;
2121
use syntax::codemap::span;
2222
use syntax::opt_vec;
2323
use syntax::print::pprust::expr_to_str;
24-
use syntax::{oldvisit, ast_util};
24+
use syntax::{visit,ast_util};
25+
use syntax::visit::Visitor;
2526

2627
// Kind analysis pass.
2728
//
@@ -58,6 +59,29 @@ pub struct Context {
5859
current_item: NodeId
5960
}
6061

62+
struct KindAnalysisVisitor;
63+
64+
impl Visitor<Context> for KindAnalysisVisitor {
65+
66+
fn visit_expr(&mut self, ex:@expr, e:Context) {
67+
check_expr(self, ex, e);
68+
}
69+
70+
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&fn_decl, b:&Block, s:span, n:NodeId, e:Context) {
71+
check_fn(self, fk, fd, b, s, n, e);
72+
}
73+
74+
fn visit_ty(&mut self, t:&Ty, e:Context) {
75+
check_ty(self, t, e);
76+
}
77+
fn visit_item(&mut self, i:@item, e:Context) {
78+
check_item(self, i, e);
79+
}
80+
fn visit_block(&mut self, b:&Block, e:Context) {
81+
check_block(self, b, e);
82+
}
83+
}
84+
6185
pub fn check_crate(tcx: ty::ctxt,
6286
method_map: typeck::method_map,
6387
crate: &Crate) {
@@ -66,15 +90,8 @@ pub fn check_crate(tcx: ty::ctxt,
6690
method_map: method_map,
6791
current_item: -1
6892
};
69-
let visit = oldvisit::mk_vt(@oldvisit::Visitor {
70-
visit_expr: check_expr,
71-
visit_fn: check_fn,
72-
visit_ty: check_ty,
73-
visit_item: check_item,
74-
visit_block: check_block,
75-
.. *oldvisit::default_visitor()
76-
});
77-
oldvisit::visit_crate(crate, (ctx, visit));
93+
let mut visit = KindAnalysisVisitor;
94+
visit::walk_crate(&mut visit, crate, ctx);
7895
tcx.sess.abort_if_errors();
7996
}
8097

@@ -108,12 +125,13 @@ fn check_struct_safe_for_destructor(cx: Context,
108125
}
109126
}
110127

111-
fn check_block(block: &Block,
112-
(cx, visitor): (Context, oldvisit::vt<Context>)) {
113-
oldvisit::visit_block(block, (cx, visitor));
128+
fn check_block(visitor: &mut KindAnalysisVisitor,
129+
block: &Block,
130+
cx: Context) {
131+
visit::walk_block(visitor, block, cx);
114132
}
115133

116-
fn check_item(item: @item, (cx, visitor): (Context, oldvisit::vt<Context>)) {
134+
fn check_item(visitor: &mut KindAnalysisVisitor, item: @item, cx: Context) {
117135
// If this is a destructor, check kinds.
118136
if !attr::contains_name(item.attrs, "unsafe_destructor") {
119137
match item.node {
@@ -153,7 +171,7 @@ fn check_item(item: @item, (cx, visitor): (Context, oldvisit::vt<Context>)) {
153171
}
154172

155173
let cx = Context { current_item: item.id, ..cx };
156-
oldvisit::visit_item(item, (cx, visitor));
174+
visit::walk_item(visitor, item, cx);
157175
}
158176

159177
// Yields the appropriate function to check the kind of closed over
@@ -227,13 +245,13 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
227245
// Check that the free variables used in a shared/sendable closure conform
228246
// to the copy/move kind bounds. Then recursively check the function body.
229247
fn check_fn(
230-
fk: &oldvisit::fn_kind,
248+
v: &mut KindAnalysisVisitor,
249+
fk: &visit::fn_kind,
231250
decl: &fn_decl,
232251
body: &Block,
233252
sp: span,
234253
fn_id: NodeId,
235-
(cx, v): (Context,
236-
oldvisit::vt<Context>)) {
254+
cx: Context) {
237255

238256
// Check kinds on free variables:
239257
do with_appropriate_checker(cx, fn_id) |chk| {
@@ -243,10 +261,10 @@ fn check_fn(
243261
}
244262
}
245263

246-
oldvisit::visit_fn(fk, decl, body, sp, fn_id, (cx, v));
264+
visit::walk_fn(v, fk, decl, body, sp, fn_id, cx);
247265
}
248266

249-
pub fn check_expr(e: @expr, (cx, v): (Context, oldvisit::vt<Context>)) {
267+
pub fn check_expr(v: &mut KindAnalysisVisitor, e: @expr, cx: Context) {
250268
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));
251269

252270
// Handle any kind bounds on type parameters
@@ -311,10 +329,10 @@ pub fn check_expr(e: @expr, (cx, v): (Context, oldvisit::vt<Context>)) {
311329
}
312330
_ => {}
313331
}
314-
oldvisit::visit_expr(e, (cx, v));
332+
visit::walk_expr(v, e, cx);
315333
}
316334

317-
fn check_ty(aty: &Ty, (cx, v): (Context, oldvisit::vt<Context>)) {
335+
fn check_ty(v: &mut KindAnalysisVisitor, aty: &Ty, cx: Context) {
318336
match aty.node {
319337
ty_path(_, _, id) => {
320338
let r = cx.tcx.node_type_substs.find(&id);
@@ -329,7 +347,7 @@ fn check_ty(aty: &Ty, (cx, v): (Context, oldvisit::vt<Context>)) {
329347
}
330348
_ => {}
331349
}
332-
oldvisit::visit_ty(aty, (cx, v));
350+
visit::walk_ty(v, aty, cx);
333351
}
334352

335353
// Calls "any_missing" if any bounds were missing.

0 commit comments

Comments
 (0)