@@ -139,8 +139,8 @@ use std::at_vec;
139
139
use std:: hashmap:: { HashSet , HashMap } ;
140
140
use syntax:: ast:: * ;
141
141
use syntax:: ast_util;
142
- use syntax:: oldvisit ;
143
- use syntax:: oldvisit :: vt ;
142
+ use syntax:: visit ;
143
+ use syntax:: visit :: Visitor ;
144
144
use syntax:: codemap:: span;
145
145
146
146
#[ deriving( Encodable , Decodable ) ]
@@ -190,16 +190,26 @@ enum UseMode {
190
190
Read // Read no matter what the type.
191
191
}
192
192
193
+ struct ComputeModesVisitor ;
194
+
195
+ impl visit:: Visitor < VisitContext > for ComputeModesVisitor {
196
+ fn visit_fn ( & mut self , fk : & visit:: fn_kind , fd : & fn_decl ,
197
+ b : & Block , s : span , n : NodeId , e : VisitContext ) {
198
+ compute_modes_for_fn ( * self , fk, fd, b, s, n, e) ;
199
+ }
200
+ fn visit_expr ( & mut self , ex: @expr, e : VisitContext ) {
201
+ compute_modes_for_expr ( * self , ex, e) ;
202
+ }
203
+ fn visit_local ( & mut self , l : @Local , e : VisitContext ) {
204
+ compute_modes_for_local ( * self , l, e) ;
205
+ }
206
+ }
207
+
193
208
pub fn compute_moves ( tcx : ty:: ctxt ,
194
209
method_map : method_map ,
195
210
crate : & Crate ) -> MoveMaps
196
211
{
197
- let visitor = oldvisit:: mk_vt ( @oldvisit:: Visitor {
198
- visit_fn : compute_modes_for_fn,
199
- visit_expr : compute_modes_for_expr,
200
- visit_local : compute_modes_for_local,
201
- .. * oldvisit:: default_visitor ( )
202
- } ) ;
212
+ let mut visitor = ComputeModesVisitor ;
203
213
let visit_cx = VisitContext {
204
214
tcx : tcx,
205
215
method_map : method_map,
@@ -209,7 +219,7 @@ pub fn compute_moves(tcx: ty::ctxt,
209
219
moved_variables_set : @mut HashSet :: new ( )
210
220
}
211
221
} ;
212
- oldvisit :: visit_crate ( crate , ( visit_cx , visitor ) ) ;
222
+ visit :: walk_crate ( & mut visitor , crate , visit_cx ) ;
213
223
return visit_cx. move_maps ;
214
224
}
215
225
@@ -227,43 +237,44 @@ pub fn moved_variable_node_id_from_def(def: def) -> Option<NodeId> {
227
237
///////////////////////////////////////////////////////////////////////////
228
238
// Expressions
229
239
230
- fn compute_modes_for_local < ' a > ( local : @ Local ,
231
- ( cx , v ) : ( VisitContext ,
232
- vt < VisitContext > ) ) {
240
+ fn compute_modes_for_local < ' a > ( v : ComputeModesVisitor ,
241
+ local : @ Local ,
242
+ cx : VisitContext ) {
233
243
cx. use_pat ( local. pat ) ;
234
244
for & init in local. init . iter ( ) {
235
245
cx. use_expr ( init, Read , v) ;
236
246
}
237
247
}
238
248
239
- fn compute_modes_for_fn ( fk : & oldvisit:: fn_kind ,
249
+ fn compute_modes_for_fn ( v : ComputeModesVisitor ,
250
+ fk : & visit:: fn_kind ,
240
251
decl : & fn_decl ,
241
252
body : & Block ,
242
253
span : span ,
243
254
id : NodeId ,
244
- ( cx , v ) : ( VisitContext ,
245
- vt < VisitContext > ) ) {
255
+ cx : VisitContext ) {
256
+ let mut v = v ;
246
257
for a in decl. inputs . iter ( ) {
247
258
cx. use_pat ( a. pat ) ;
248
259
}
249
- oldvisit :: visit_fn ( fk, decl, body, span, id, ( cx , v ) ) ;
260
+ visit :: walk_fn ( & mut v , fk, decl, body, span, id, cx ) ;
250
261
}
251
262
252
- fn compute_modes_for_expr ( expr : @expr ,
253
- ( cx , v ) : ( VisitContext ,
254
- vt < VisitContext > ) )
263
+ fn compute_modes_for_expr ( v : ComputeModesVisitor ,
264
+ expr : @expr ,
265
+ cx : VisitContext )
255
266
{
256
267
cx. consume_expr ( expr, v) ;
257
268
}
258
269
259
270
impl VisitContext {
260
- pub fn consume_exprs ( & self , exprs : & [ @expr] , visitor : vt < VisitContext > ) {
271
+ pub fn consume_exprs ( & self , exprs : & [ @expr] , visitor : ComputeModesVisitor ) {
261
272
for expr in exprs. iter ( ) {
262
273
self . consume_expr ( * expr, visitor) ;
263
274
}
264
275
}
265
276
266
- pub fn consume_expr ( & self , expr: @expr, visitor : vt < VisitContext > ) {
277
+ pub fn consume_expr ( & self , expr: @expr, visitor : ComputeModesVisitor ) {
267
278
/*!
268
279
* Indicates that the value of `expr` will be consumed,
269
280
* meaning either copied or moved depending on its type.
@@ -281,7 +292,7 @@ impl VisitContext {
281
292
} ;
282
293
}
283
294
284
- pub fn consume_block ( & self , blk : & Block , visitor : vt < VisitContext > ) {
295
+ pub fn consume_block ( & self , blk : & Block , visitor : ComputeModesVisitor ) {
285
296
/*!
286
297
* Indicates that the value of `blk` will be consumed,
287
298
* meaning either copied or moved depending on its type.
@@ -290,7 +301,8 @@ impl VisitContext {
290
301
debug ! ( "consume_block(blk.id=%?)" , blk. id) ;
291
302
292
303
for stmt in blk. stmts . iter ( ) {
293
- ( visitor. visit_stmt ) ( * stmt, ( * self , visitor) ) ;
304
+ let mut v = visitor;
305
+ v. visit_stmt ( * stmt, * self ) ;
294
306
}
295
307
296
308
for tail_expr in blk. expr . iter ( ) {
@@ -301,7 +313,7 @@ impl VisitContext {
301
313
pub fn use_expr ( & self ,
302
314
expr: @expr,
303
315
expr_mode : UseMode ,
304
- visitor : vt < VisitContext > ) {
316
+ visitor : ComputeModesVisitor ) {
305
317
/*!
306
318
* Indicates that `expr` is used with a given mode. This will
307
319
* in turn trigger calls to the subcomponents of `expr`.
@@ -570,7 +582,7 @@ impl VisitContext {
570
582
expr : & expr ,
571
583
receiver_expr : @expr,
572
584
arg_exprs : & [ @expr] ,
573
- visitor : vt < VisitContext > )
585
+ visitor : ComputeModesVisitor )
574
586
-> bool {
575
587
if !self . method_map . contains_key ( & expr. id ) {
576
588
return false ;
@@ -587,7 +599,7 @@ impl VisitContext {
587
599
return true ;
588
600
}
589
601
590
- pub fn consume_arm ( & self , arm : & arm , visitor : vt < VisitContext > ) {
602
+ pub fn consume_arm ( & self , arm : & arm , visitor : ComputeModesVisitor ) {
591
603
for pat in arm. pats . iter ( ) {
592
604
self . use_pat ( * pat) ;
593
605
}
@@ -630,21 +642,21 @@ impl VisitContext {
630
642
631
643
pub fn use_receiver ( & self ,
632
644
receiver_expr : @expr,
633
- visitor : vt < VisitContext > ) {
645
+ visitor : ComputeModesVisitor ) {
634
646
self . use_fn_arg ( receiver_expr, visitor) ;
635
647
}
636
648
637
649
pub fn use_fn_args ( & self ,
638
650
_: NodeId ,
639
651
arg_exprs : & [ @expr] ,
640
- visitor : vt < VisitContext > ) {
652
+ visitor : ComputeModesVisitor ) {
641
653
//! Uses the argument expressions.
642
654
for arg_expr in arg_exprs. iter ( ) {
643
655
self . use_fn_arg ( * arg_expr, visitor) ;
644
656
}
645
657
}
646
658
647
- pub fn use_fn_arg ( & self , arg_expr: @expr, visitor : vt < VisitContext > ) {
659
+ pub fn use_fn_arg ( & self , arg_expr: @expr, visitor : ComputeModesVisitor ) {
648
660
//! Uses the argument.
649
661
self . consume_expr ( arg_expr, visitor)
650
662
}
0 commit comments