Skip to content

Commit 54ee3d0

Browse files
committed
Port check_match from oldvisit to <V:Visitor> trait API.
1 parent 3563411 commit 54ee3d0

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

src/librustc/middle/check_match.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,50 @@ use extra::sort;
2525
use syntax::ast::*;
2626
use syntax::ast_util::{unguarded_pat, walk_pat};
2727
use syntax::codemap::{span, dummy_sp, spanned};
28-
use syntax::oldvisit;
28+
use syntax::visit;
29+
use syntax::visit::{Visitor,fn_kind};
2930

3031
pub struct MatchCheckCtxt {
3132
tcx: ty::ctxt,
3233
method_map: method_map,
3334
moves_map: moves::MovesMap
3435
}
3536

37+
struct CheckMatchVisitor {
38+
cx: @MatchCheckCtxt
39+
}
40+
41+
impl Visitor<()> for CheckMatchVisitor {
42+
fn visit_expr(&mut self, ex:@expr, e:()) {
43+
check_expr(self, self.cx, ex, e);
44+
}
45+
fn visit_local(&mut self, l:@Local, e:()) {
46+
check_local(self, self.cx, l, e);
47+
}
48+
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl, b:&Block, s:span, n:NodeId, e:()) {
49+
check_fn(self, self.cx, fk, fd, b, s, n, e);
50+
}
51+
}
52+
3653
pub fn check_crate(tcx: ty::ctxt,
3754
method_map: method_map,
3855
moves_map: moves::MovesMap,
3956
crate: &Crate) {
4057
let cx = @MatchCheckCtxt {tcx: tcx,
4158
method_map: method_map,
4259
moves_map: moves_map};
43-
oldvisit::visit_crate(crate, ((), oldvisit::mk_vt(@oldvisit::Visitor {
44-
visit_expr: |a,b| check_expr(cx, a, b),
45-
visit_local: |a,b| check_local(cx, a, b),
46-
visit_fn: |kind, decl, body, sp, id, (e, v)|
47-
check_fn(cx, kind, decl, body, sp, id, (e, v)),
48-
.. *oldvisit::default_visitor::<()>()
49-
})));
60+
let mut v = CheckMatchVisitor { cx: cx };
61+
62+
visit::walk_crate(&mut v, crate, ());
63+
5064
tcx.sess.abort_if_errors();
5165
}
5266

53-
pub fn check_expr(cx: @MatchCheckCtxt,
67+
pub fn check_expr(v: &mut CheckMatchVisitor,
68+
cx: @MatchCheckCtxt,
5469
ex: @expr,
55-
(s, v): ((), oldvisit::vt<()>)) {
56-
oldvisit::visit_expr(ex, (s, v));
70+
s: ()) {
71+
visit::walk_expr(v, ex, s);
5772
match ex.node {
5873
expr_match(scrut, ref arms) => {
5974
// First, check legality of move bindings.
@@ -787,10 +802,11 @@ pub fn default(cx: &MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
787802
else { None }
788803
}
789804

790-
pub fn check_local(cx: &MatchCheckCtxt,
805+
pub fn check_local(v: &mut CheckMatchVisitor,
806+
cx: &MatchCheckCtxt,
791807
loc: @Local,
792-
(s, v): ((), oldvisit::vt<()>)) {
793-
oldvisit::visit_local(loc, (s, v));
808+
s: ()) {
809+
visit::walk_local(v, loc, s);
794810
if is_refutable(cx, loc.pat) {
795811
cx.tcx.sess.span_err(loc.pat.span,
796812
"refutable pattern in local binding");
@@ -800,15 +816,15 @@ pub fn check_local(cx: &MatchCheckCtxt,
800816
check_legality_of_move_bindings(cx, false, [ loc.pat ]);
801817
}
802818

803-
pub fn check_fn(cx: &MatchCheckCtxt,
804-
kind: &oldvisit::fn_kind,
819+
pub fn check_fn(v: &mut CheckMatchVisitor,
820+
cx: &MatchCheckCtxt,
821+
kind: &visit::fn_kind,
805822
decl: &fn_decl,
806823
body: &Block,
807824
sp: span,
808825
id: NodeId,
809-
(s, v): ((),
810-
oldvisit::vt<()>)) {
811-
oldvisit::visit_fn(kind, decl, body, sp, id, (s, v));
826+
s: ()) {
827+
visit::walk_fn(v, kind, decl, body, sp, id, s);
812828
for input in decl.inputs.iter() {
813829
if is_refutable(cx, input.pat) {
814830
cx.tcx.sess.span_err(input.pat.span,

0 commit comments

Comments
 (0)