Skip to content

Commit 7328f4c

Browse files
committed
port type_use.rs from oldvisit to <V:Visitor> trait.
1 parent 23ce08a commit 7328f4c

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/librustc/middle/trans/type_use.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ use syntax::ast::*;
4242
use syntax::ast_map;
4343
use syntax::ast_util;
4444
use syntax::parse::token;
45-
use syntax::oldvisit;
45+
use syntax::visit;
46+
use syntax::visit::Visitor;
4647

4748
pub type type_uses = uint; // Bitmask
4849
pub static use_repr: uint = 1; /* Dependency on size/alignment/mode and
4950
take/drop glue */
5051
pub static use_tydesc: uint = 2; /* Takes the tydesc, or compares */
5152
pub static use_all: uint = use_repr|use_tydesc;
5253

53-
54+
#[deriving(Clone)]
5455
pub struct Context {
5556
ccx: @mut CrateContext,
5657
uses: @mut ~[type_uses]
@@ -416,28 +417,39 @@ pub fn mark_for_expr(cx: &Context, e: &expr) {
416417
}
417418
}
418419

419-
pub fn handle_body(cx: &Context, body: &Block) {
420-
let v = oldvisit::mk_vt(@oldvisit::Visitor {
421-
visit_expr: |e, (cx, v)| {
422-
oldvisit::visit_expr(e, (cx, v));
420+
struct TypeUseVisitor;
421+
422+
impl<'self> Visitor<&'self Context> for TypeUseVisitor {
423+
424+
fn visit_expr<'a>(&mut self, e:@expr, cx: &'a Context) {
425+
visit::walk_expr(self, e, cx);
423426
mark_for_expr(cx, e);
424-
},
425-
visit_local: |l, (cx, v)| {
426-
oldvisit::visit_local(l, (cx, v));
427+
}
428+
429+
fn visit_local<'a>(&mut self, l:@Local, cx: &'a Context) {
430+
visit::walk_local(self, l, cx);
427431
node_type_needs(cx, use_repr, l.id);
428-
},
429-
visit_pat: |p, (cx, v)| {
430-
oldvisit::visit_pat(p, (cx, v));
432+
}
433+
434+
fn visit_pat<'a>(&mut self, p:@pat, cx: &'a Context) {
435+
visit::walk_pat(self, p, cx);
431436
node_type_needs(cx, use_repr, p.id);
432-
},
433-
visit_block: |b, (cx, v)| {
434-
oldvisit::visit_block(b, (cx, v));
437+
}
438+
439+
fn visit_block<'a>(&mut self, b:&Block, cx: &'a Context) {
440+
visit::walk_block(self, b, cx);
435441
for e in b.expr.iter() {
436442
node_type_needs(cx, use_repr, e.id);
437443
}
438-
},
439-
visit_item: |_i, (_cx, _v)| { },
440-
..*oldvisit::default_visitor()
441-
});
442-
(v.visit_block)(body, (cx, v));
444+
}
445+
446+
fn visit_item<'a>(&mut self, _:@item, _: &'a Context) {
447+
// do nothing
448+
}
449+
450+
}
451+
452+
pub fn handle_body(cx: &Context, body: &Block) {
453+
let mut v = TypeUseVisitor;
454+
v.visit_block(body, cx);
443455
}

0 commit comments

Comments
 (0)