Skip to content

Commit 78dd07b

Browse files
committed
Ported rusti::utils from oldvisit to <V:Visitor> trait API.
1 parent e524781 commit 78dd07b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/librusti/utils.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@ use syntax::ast;
1313
use syntax::print::pp;
1414
use syntax::print::pprust;
1515
use syntax::parse::token;
16+
use syntax::visit;
1617

17-
pub fn each_binding(l: @ast::Local, f: @fn(&ast::Path, ast::NodeId)) {
18-
use syntax::oldvisit;
18+
struct EachBindingVisitor {
19+
f: @fn(&ast::Path, ast::NodeId)
20+
}
1921

20-
let vt = oldvisit::mk_simple_visitor(
21-
@oldvisit::SimpleVisitor {
22-
visit_pat: |pat| {
22+
impl visit::Visitor<()> for EachBindingVisitor {
23+
fn visit_pat(&mut self, pat:@ast::pat, _:()) {
2324
match pat.node {
2425
ast::pat_ident(_, ref path, _) => {
25-
f(path, pat.id);
26+
(self.f)(path, pat.id);
2627
}
2728
_ => {}
2829
}
29-
},
30-
.. *oldvisit::default_simple_visitor()
31-
}
32-
);
33-
(vt.visit_pat)(l.pat, ((), vt));
30+
31+
visit::walk_pat(self, pat, ());
32+
}
33+
}
34+
35+
pub fn each_binding(l: @ast::Local, f: @fn(&ast::Path, ast::NodeId)) {
36+
use syntax::visit::Visitor;
37+
38+
let mut vt = EachBindingVisitor{ f: f };
39+
40+
vt.visit_pat(l.pat, ());
3441
}
3542

3643
/// A utility function that hands off a pretty printer to a callback.

0 commit comments

Comments
 (0)