@@ -43,7 +43,8 @@ use syntax::ast::{ManagedSigil, OwnedSigil, BorrowedSigil};
43
43
use syntax:: ast:: { def_arg, def_binding, def_local, def_self, def_upvar} ;
44
44
use syntax:: ast;
45
45
use syntax:: codemap:: span;
46
- use syntax:: oldvisit;
46
+ use syntax:: visit;
47
+ use syntax:: visit:: Visitor ;
47
48
48
49
pub struct Rcx {
49
50
fcx : @mut FnCtxt ,
@@ -53,8 +54,6 @@ pub struct Rcx {
53
54
repeating_scope : ast:: NodeId ,
54
55
}
55
56
56
- pub type rvt = oldvisit:: vt < @mut Rcx > ;
57
-
58
57
fn encl_region_of_def ( fcx : @mut FnCtxt , def : ast:: def ) -> ty:: Region {
59
58
let tcx = fcx. tcx ( ) ;
60
59
match def {
@@ -146,8 +145,8 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
146
145
repeating_scope : e. id } ;
147
146
if fcx. err_count_since_creation ( ) == 0 {
148
147
// regionck assumes typeck succeeded
149
- let v = regionck_visitor ( ) ;
150
- ( v. visit_expr ) ( e, ( rcx, v ) ) ;
148
+ let mut v = regionck_visitor ( ) ;
149
+ v. visit_expr ( e, rcx) ;
151
150
}
152
151
fcx. infcx ( ) . resolve_regions ( ) ;
153
152
}
@@ -157,55 +156,62 @@ pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::Block) {
157
156
repeating_scope : blk. id } ;
158
157
if fcx. err_count_since_creation ( ) == 0 {
159
158
// regionck assumes typeck succeeded
160
- let v = regionck_visitor ( ) ;
161
- ( v. visit_block ) ( blk, ( rcx, v ) ) ;
159
+ let mut v = regionck_visitor ( ) ;
160
+ v. visit_block ( blk, rcx) ;
162
161
}
163
162
fcx. infcx ( ) . resolve_regions ( ) ;
164
163
}
165
164
166
- fn regionck_visitor ( ) -> rvt {
165
+ struct RegionckVisitor ;
166
+
167
+ impl Visitor < @mut Rcx > for RegionckVisitor {
167
168
// (*) FIXME(#3238) should use visit_pat, not visit_arm/visit_local,
168
169
// However, right now we run into an issue whereby some free
169
170
// regions are not properly related if they appear within the
170
171
// types of arguments that must be inferred. This could be
171
172
// addressed by deferring the construction of the region
172
173
// hierarchy, and in particular the relationships between free
173
174
// regions, until regionck, as described in #3238.
174
- oldvisit:: mk_vt ( @oldvisit:: Visitor {
175
- visit_item : visit_item,
176
- visit_expr : visit_expr,
175
+
176
+ fn visit_item ( & mut self , i : @ast:: item , e : @mut Rcx ) { visit_item ( self , i, e) ; }
177
+
178
+ fn visit_expr ( & mut self , ex : @ast:: expr , e : @mut Rcx ) { visit_expr ( self , ex, e) ; }
177
179
178
180
//visit_pat: visit_pat, // (*) see above
179
- visit_arm : visit_arm,
180
- visit_local : visit_local,
181
181
182
- visit_block : visit_block,
183
- .. * oldvisit:: default_visitor ( )
184
- } )
182
+ fn visit_arm ( & mut self , a : & ast:: arm , e : @mut Rcx ) { visit_arm ( self , a, e) ; }
183
+
184
+ fn visit_local ( & mut self , l : @ast:: Local , e : @mut Rcx ) { visit_local ( self , l, e) ; }
185
+
186
+ fn visit_block ( & mut self , b : & ast:: Block , e : @mut Rcx ) { visit_block ( self , b, e) ; }
187
+ }
188
+
189
+ fn regionck_visitor ( ) -> RegionckVisitor {
190
+ RegionckVisitor
185
191
}
186
192
187
- fn visit_item ( _item : @ast:: item , ( _rcx, _v ) : ( @mut Rcx , rvt ) ) {
193
+ fn visit_item ( _v : & mut RegionckVisitor , _item : @ast:: item , _rcx : @mut Rcx ) {
188
194
// Ignore items
189
195
}
190
196
191
- fn visit_block ( b : & ast:: Block , ( rcx, v ) : ( @mut Rcx , rvt ) ) {
197
+ fn visit_block ( v : & mut RegionckVisitor , b : & ast:: Block , rcx : @mut Rcx ) {
192
198
rcx. fcx . tcx ( ) . region_maps . record_cleanup_scope ( b. id ) ;
193
- oldvisit :: visit_block ( b , ( rcx , v ) ) ;
199
+ visit :: walk_block ( v , b , rcx ) ;
194
200
}
195
201
196
- fn visit_arm ( arm : & ast:: arm , ( rcx, v ) : ( @mut Rcx , rvt ) ) {
202
+ fn visit_arm ( v : & mut RegionckVisitor , arm : & ast:: arm , rcx : @mut Rcx ) {
197
203
// see above
198
204
for & p in arm. pats . iter ( ) {
199
205
constrain_bindings_in_pat ( p, rcx) ;
200
206
}
201
207
202
- oldvisit :: visit_arm ( arm , ( rcx , v ) ) ;
208
+ visit :: walk_arm ( v , arm , rcx ) ;
203
209
}
204
210
205
- fn visit_local ( l : @ast:: Local , ( rcx, v ) : ( @mut Rcx , rvt ) ) {
211
+ fn visit_local ( v : & mut RegionckVisitor , l : @ast:: Local , rcx : @mut Rcx ) {
206
212
// see above
207
213
constrain_bindings_in_pat ( l. pat , rcx) ;
208
- oldvisit :: visit_local ( l , ( rcx , v ) ) ;
214
+ visit :: walk_local ( v , l , rcx ) ;
209
215
}
210
216
211
217
fn constrain_bindings_in_pat ( pat : @ast:: pat , rcx : @mut Rcx ) {
@@ -242,7 +248,7 @@ fn constrain_bindings_in_pat(pat: @ast::pat, rcx: @mut Rcx) {
242
248
}
243
249
}
244
250
245
- fn visit_expr ( expr : @ast:: expr , ( rcx, v ) : ( @mut Rcx , rvt ) ) {
251
+ fn visit_expr ( v : & mut RegionckVisitor , expr : @ast:: expr , rcx : @mut Rcx ) {
246
252
debug ! ( "regionck::visit_expr(e=%s, repeating_scope=%?)" ,
247
253
expr. repr( rcx. fcx. tcx( ) ) , rcx. repeating_scope) ;
248
254
@@ -330,13 +336,13 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
330
336
constrain_callee ( rcx, callee. id , expr, callee) ;
331
337
constrain_call ( rcx, callee. id , expr, None , * args, false ) ;
332
338
333
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
339
+ visit :: walk_expr ( v , expr , rcx ) ;
334
340
}
335
341
336
342
ast:: expr_method_call( callee_id, arg0, _, _, ref args, _) => {
337
343
constrain_call ( rcx, callee_id, expr, Some ( arg0) , * args, false ) ;
338
344
339
- oldvisit :: visit_expr ( expr, ( rcx, v ) ) ;
345
+ visit :: walk_expr ( v , expr, rcx) ;
340
346
}
341
347
342
348
ast:: expr_index( callee_id, lhs, rhs) |
@@ -348,30 +354,30 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
348
354
// should be converted to an adjustment!
349
355
constrain_call ( rcx, callee_id, expr, Some ( lhs) , [ rhs] , true ) ;
350
356
351
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
357
+ visit :: walk_expr ( v , expr , rcx ) ;
352
358
}
353
359
354
360
ast:: expr_unary( callee_id, _, lhs) if has_method_map => {
355
361
// As above.
356
362
constrain_call ( rcx, callee_id, expr, Some ( lhs) , [ ] , true ) ;
357
363
358
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
364
+ visit :: walk_expr ( v , expr , rcx ) ;
359
365
}
360
366
361
367
ast:: expr_unary( _, ast:: deref, base) => {
362
368
// For *a, the lifetime of a must enclose the deref
363
369
let base_ty = rcx. resolve_node_type ( base. id ) ;
364
370
constrain_derefs ( rcx, expr, 1 , base_ty) ;
365
371
366
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
372
+ visit :: walk_expr ( v , expr , rcx ) ;
367
373
}
368
374
369
375
ast:: expr_index( _, vec_expr, _) => {
370
376
// For a[b], the lifetime of a must enclose the deref
371
377
let vec_type = rcx. resolve_expr_type_adjusted ( vec_expr) ;
372
378
constrain_index ( rcx, expr, vec_type) ;
373
379
374
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
380
+ visit :: walk_expr ( v , expr , rcx ) ;
375
381
}
376
382
377
383
ast:: expr_cast( source, _) => {
@@ -401,7 +407,7 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
401
407
_ => ( )
402
408
}
403
409
404
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
410
+ visit :: walk_expr ( v , expr , rcx ) ;
405
411
}
406
412
407
413
ast:: expr_addr_of( _, base) => {
@@ -417,13 +423,13 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
417
423
let ty0 = rcx. resolve_node_type ( expr. id ) ;
418
424
constrain_regions_in_type ( rcx, ty:: re_scope ( expr. id ) ,
419
425
infer:: AddrOf ( expr. span ) , ty0) ;
420
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
426
+ visit :: walk_expr ( v , expr , rcx ) ;
421
427
}
422
428
423
429
ast:: expr_match( discr, ref arms) => {
424
430
guarantor:: for_match ( rcx, discr, * arms) ;
425
431
426
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
432
+ visit :: walk_expr ( v , expr , rcx ) ;
427
433
}
428
434
429
435
ast:: expr_fn_block( * ) => {
@@ -432,29 +438,29 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
432
438
433
439
ast:: expr_loop( ref body, _) => {
434
440
let repeating_scope = rcx. set_repeating_scope ( body. id ) ;
435
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
441
+ visit :: walk_expr ( v , expr , rcx ) ;
436
442
rcx. set_repeating_scope ( repeating_scope) ;
437
443
}
438
444
439
445
ast:: expr_while( cond, ref body) => {
440
446
let repeating_scope = rcx. set_repeating_scope ( cond. id ) ;
441
- ( v. visit_expr ) ( cond, ( rcx, v ) ) ;
447
+ v. visit_expr ( cond, rcx) ;
442
448
443
449
rcx. set_repeating_scope ( body. id ) ;
444
- ( v. visit_block ) ( body, ( rcx, v ) ) ;
450
+ v. visit_block ( body, rcx) ;
445
451
446
452
rcx. set_repeating_scope ( repeating_scope) ;
447
453
}
448
454
449
455
_ => {
450
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
456
+ visit :: walk_expr ( v , expr , rcx ) ;
451
457
}
452
458
}
453
459
}
454
460
455
461
fn check_expr_fn_block ( rcx : @mut Rcx ,
456
462
expr : @ast:: expr ,
457
- v : rvt ) {
463
+ v : & mut RegionckVisitor ) {
458
464
let tcx = rcx. fcx . tcx ( ) ;
459
465
match expr. node {
460
466
ast:: expr_fn_block( _, ref body) => {
@@ -483,7 +489,7 @@ fn check_expr_fn_block(rcx: @mut Rcx,
483
489
}
484
490
485
491
let repeating_scope = rcx. set_repeating_scope ( body. id ) ;
486
- oldvisit :: visit_expr ( expr , ( rcx , v ) ) ;
492
+ visit :: walk_expr ( v , expr , rcx ) ;
487
493
rcx. set_repeating_scope ( repeating_scope) ;
488
494
}
489
495
0 commit comments