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