@@ -25,35 +25,50 @@ use extra::sort;
25
25
use syntax:: ast:: * ;
26
26
use syntax:: ast_util:: { unguarded_pat, walk_pat} ;
27
27
use syntax:: codemap:: { span, dummy_sp, spanned} ;
28
- use syntax:: oldvisit;
28
+ use syntax:: visit;
29
+ use syntax:: visit:: { Visitor , fn_kind} ;
29
30
30
31
pub struct MatchCheckCtxt {
31
32
tcx : ty:: ctxt ,
32
33
method_map : method_map ,
33
34
moves_map : moves:: MovesMap
34
35
}
35
36
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
+
36
53
pub fn check_crate ( tcx : ty:: ctxt ,
37
54
method_map : method_map ,
38
55
moves_map : moves:: MovesMap ,
39
56
crate : & Crate ) {
40
57
let cx = @MatchCheckCtxt { tcx : tcx,
41
58
method_map : method_map,
42
59
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
+
50
64
tcx. sess . abort_if_errors ( ) ;
51
65
}
52
66
53
- pub fn check_expr ( cx : @MatchCheckCtxt ,
67
+ pub fn check_expr ( v : & mut CheckMatchVisitor ,
68
+ cx : @MatchCheckCtxt ,
54
69
ex: @expr,
55
- ( s , v ) : ( ( ) , oldvisit :: vt < ( ) > ) ) {
56
- oldvisit :: visit_expr ( ex , ( s , v ) ) ;
70
+ s : ( ) ) {
71
+ visit :: walk_expr ( v , ex , s ) ;
57
72
match ex. node {
58
73
expr_match( scrut, ref arms) => {
59
74
// First, check legality of move bindings.
@@ -787,10 +802,11 @@ pub fn default(cx: &MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
787
802
else { None }
788
803
}
789
804
790
- pub fn check_local ( cx : & MatchCheckCtxt ,
805
+ pub fn check_local ( v : & mut CheckMatchVisitor ,
806
+ cx : & MatchCheckCtxt ,
791
807
loc : @Local ,
792
- ( s , v ) : ( ( ) , oldvisit :: vt < ( ) > ) ) {
793
- oldvisit :: visit_local ( loc , ( s , v ) ) ;
808
+ s : ( ) ) {
809
+ visit :: walk_local ( v , loc , s ) ;
794
810
if is_refutable ( cx, loc. pat ) {
795
811
cx. tcx . sess . span_err ( loc. pat . span ,
796
812
"refutable pattern in local binding" ) ;
@@ -800,15 +816,15 @@ pub fn check_local(cx: &MatchCheckCtxt,
800
816
check_legality_of_move_bindings ( cx, false , [ loc. pat ] ) ;
801
817
}
802
818
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 ,
805
822
decl : & fn_decl ,
806
823
body : & Block ,
807
824
sp : span ,
808
825
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) ;
812
828
for input in decl. inputs . iter ( ) {
813
829
if is_refutable ( cx, input. pat ) {
814
830
cx. tcx . sess . span_err ( input. pat . span ,
0 commit comments