@@ -21,7 +21,8 @@ use syntax::attr;
21
21
use syntax:: codemap:: span;
22
22
use syntax:: opt_vec;
23
23
use syntax:: print:: pprust:: expr_to_str;
24
- use syntax:: { oldvisit, ast_util} ;
24
+ use syntax:: { visit, ast_util} ;
25
+ use syntax:: visit:: Visitor ;
25
26
26
27
// Kind analysis pass.
27
28
//
@@ -58,6 +59,29 @@ pub struct Context {
58
59
current_item : NodeId
59
60
}
60
61
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
+
61
85
pub fn check_crate ( tcx : ty:: ctxt ,
62
86
method_map : typeck:: method_map ,
63
87
crate : & Crate ) {
@@ -66,15 +90,8 @@ pub fn check_crate(tcx: ty::ctxt,
66
90
method_map : method_map,
67
91
current_item : -1
68
92
} ;
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) ;
78
95
tcx. sess . abort_if_errors ( ) ;
79
96
}
80
97
@@ -108,12 +125,13 @@ fn check_struct_safe_for_destructor(cx: Context,
108
125
}
109
126
}
110
127
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) ;
114
132
}
115
133
116
- fn check_item ( item : @item, ( cx , visitor ) : ( Context , oldvisit :: vt < Context > ) ) {
134
+ fn check_item ( visitor : & mut KindAnalysisVisitor , item: @item, cx : Context ) {
117
135
// If this is a destructor, check kinds.
118
136
if !attr:: contains_name ( item. attrs , "unsafe_destructor" ) {
119
137
match item. node {
@@ -153,7 +171,7 @@ fn check_item(item: @item, (cx, visitor): (Context, oldvisit::vt<Context>)) {
153
171
}
154
172
155
173
let cx = Context { current_item : item. id , ..cx } ;
156
- oldvisit :: visit_item ( item , ( cx , visitor ) ) ;
174
+ visit :: walk_item ( visitor , item , cx ) ;
157
175
}
158
176
159
177
// Yields the appropriate function to check the kind of closed over
@@ -227,13 +245,13 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
227
245
// Check that the free variables used in a shared/sendable closure conform
228
246
// to the copy/move kind bounds. Then recursively check the function body.
229
247
fn check_fn(
230
- fk : & oldvisit:: fn_kind ,
248
+ v : & mut KindAnalysisVisitor ,
249
+ fk : & visit:: fn_kind ,
231
250
decl : & fn_decl ,
232
251
body : & Block ,
233
252
sp : span ,
234
253
fn_id : NodeId ,
235
- ( cx, v) : ( Context ,
236
- oldvisit:: vt < Context > ) ) {
254
+ cx : Context ) {
237
255
238
256
// Check kinds on free variables:
239
257
do with_appropriate_checker ( cx, fn_id) |chk| {
@@ -243,10 +261,10 @@ fn check_fn(
243
261
}
244
262
}
245
263
246
- oldvisit :: visit_fn ( fk, decl, body, sp, fn_id, ( cx , v ) ) ;
264
+ visit :: walk_fn ( v , fk, decl, body, sp, fn_id, cx ) ;
247
265
}
248
266
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 ) {
250
268
debug ! ( "kind::check_expr(%s)" , expr_to_str( e, cx. tcx. sess. intr( ) ) ) ;
251
269
252
270
// Handle any kind bounds on type parameters
@@ -311,10 +329,10 @@ pub fn check_expr(e: @expr, (cx, v): (Context, oldvisit::vt<Context>)) {
311
329
}
312
330
_ => { }
313
331
}
314
- oldvisit :: visit_expr ( e , ( cx , v ) ) ;
332
+ visit :: walk_expr ( v , e , cx ) ;
315
333
}
316
334
317
- fn check_ty ( aty : & Ty , ( cx , v ) : ( Context , oldvisit :: vt < Context > ) ) {
335
+ fn check_ty ( v : & mut KindAnalysisVisitor , aty : & Ty , cx : Context ) {
318
336
match aty. node {
319
337
ty_path( _, _, id) => {
320
338
let r = cx. tcx . node_type_substs . find ( & id) ;
@@ -329,7 +347,7 @@ fn check_ty(aty: &Ty, (cx, v): (Context, oldvisit::vt<Context>)) {
329
347
}
330
348
_ => { }
331
349
}
332
- oldvisit :: visit_ty ( aty , ( cx , v ) ) ;
350
+ visit :: walk_ty ( v , aty , cx ) ;
333
351
}
334
352
335
353
// Calls "any_missing" if any bounds were missing.
0 commit comments