@@ -31,9 +31,7 @@ use syntax::ast;
31
31
use syntax:: ast_util:: id_range;
32
32
use syntax:: codemap:: span;
33
33
use syntax:: print:: pprust;
34
- use syntax:: visit;
35
- use syntax:: visit:: Visitor ;
36
- use syntax:: ast:: { expr, fn_kind, fn_decl, Block , NodeId , stmt, pat, Local } ;
34
+ use syntax:: oldvisit;
37
35
38
36
mod lifetime;
39
37
mod restrictions;
@@ -74,30 +72,6 @@ struct GatherLoanCtxt {
74
72
repeating_ids : ~[ ast:: NodeId ]
75
73
}
76
74
77
- struct GatherLoanVisitor ;
78
-
79
- impl visit:: Visitor < @mut GatherLoanCtxt > for GatherLoanVisitor {
80
- fn visit_expr ( & mut self , ex: @expr, e : @mut GatherLoanCtxt ) {
81
- gather_loans_in_expr ( self , ex, e) ;
82
- }
83
- fn visit_block ( & mut self , b : & Block , e : @mut GatherLoanCtxt ) {
84
- gather_loans_in_block ( self , b, e) ;
85
- }
86
- fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl , b : & Block ,
87
- s : span , n : NodeId , e : @mut GatherLoanCtxt ) {
88
- gather_loans_in_fn ( self , fk, fd, b, s, n, e) ;
89
- }
90
- fn visit_stmt ( & mut self , s: @stmt, e : @mut GatherLoanCtxt ) {
91
- add_stmt_to_map ( self , s, e) ;
92
- }
93
- fn visit_pat ( & mut self , p: @pat, e : @mut GatherLoanCtxt ) {
94
- add_pat_to_id_range ( self , p, e) ;
95
- }
96
- fn visit_local ( & mut self , l : @Local , e : @mut GatherLoanCtxt ) {
97
- gather_loans_in_local ( self , l, e) ;
98
- }
99
- }
100
-
101
75
pub fn gather_loans ( bccx : @BorrowckCtxt ,
102
76
decl : & ast:: fn_decl ,
103
77
body : & ast:: Block )
@@ -111,57 +85,64 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
111
85
move_data : @mut MoveData :: new ( )
112
86
} ;
113
87
glcx. gather_fn_arg_patterns ( decl, body) ;
114
-
115
- let mut v = GatherLoanVisitor ;
116
- v. visit_block ( body, glcx) ;
88
+ let v = oldvisit:: mk_vt ( @oldvisit:: Visitor {
89
+ visit_expr : gather_loans_in_expr,
90
+ visit_block : gather_loans_in_block,
91
+ visit_fn : gather_loans_in_fn,
92
+ visit_stmt : add_stmt_to_map,
93
+ visit_pat : add_pat_to_id_range,
94
+ visit_local : gather_loans_in_local,
95
+ .. * oldvisit:: default_visitor ( )
96
+ } ) ;
97
+ ( v. visit_block ) ( body, ( glcx, v) ) ;
117
98
return ( glcx. id_range , glcx. all_loans , glcx. move_data ) ;
118
99
}
119
100
120
- fn add_pat_to_id_range ( v : & mut GatherLoanVisitor ,
121
- p : @ast :: pat ,
122
- this : @mut GatherLoanCtxt ) {
101
+ fn add_pat_to_id_range ( p : @ast :: pat ,
102
+ ( this , v ) : ( @ mut GatherLoanCtxt ,
103
+ oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
123
104
// NB: This visitor function just adds the pat ids into the id
124
105
// range. We gather loans that occur in patterns using the
125
106
// `gather_pat()` method below. Eventually these two should be
126
107
// brought together.
127
108
this. id_range . add ( p. id ) ;
128
- visit :: walk_pat ( v , p, this) ;
109
+ oldvisit :: visit_pat ( p, ( this, v ) ) ;
129
110
}
130
111
131
- fn gather_loans_in_fn ( v : & mut GatherLoanVisitor ,
132
- fk : & fn_kind ,
112
+ fn gather_loans_in_fn ( fk : & oldvisit:: fn_kind ,
133
113
decl : & ast:: fn_decl ,
134
114
body : & ast:: Block ,
135
115
sp : span ,
136
116
id : ast:: NodeId ,
137
- this : @mut GatherLoanCtxt ) {
117
+ ( this, v) : ( @mut GatherLoanCtxt ,
118
+ oldvisit:: vt < @mut GatherLoanCtxt > ) ) {
138
119
match fk {
139
120
// Do not visit items here, the outer loop in borrowck/mod
140
121
// will visit them for us in turn.
141
- & visit :: fk_item_fn( * ) | & visit :: fk_method( * ) => {
122
+ & oldvisit :: fk_item_fn( * ) | & oldvisit :: fk_method( * ) => {
142
123
return ;
143
124
}
144
125
145
126
// Visit closures as part of the containing item.
146
- & visit :: fk_anon( * ) | & visit :: fk_fn_block( * ) => {
127
+ & oldvisit :: fk_anon( * ) | & oldvisit :: fk_fn_block( * ) => {
147
128
this. push_repeating_id ( body. id ) ;
148
- visit :: walk_fn ( v , fk, decl, body, sp, id, this) ;
129
+ oldvisit :: visit_fn ( fk, decl, body, sp, id, ( this, v ) ) ;
149
130
this. pop_repeating_id ( body. id ) ;
150
131
this. gather_fn_arg_patterns ( decl, body) ;
151
132
}
152
133
}
153
134
}
154
135
155
- fn gather_loans_in_block ( v : & mut GatherLoanVisitor ,
156
- blk : & ast :: Block ,
157
- this : @mut GatherLoanCtxt ) {
136
+ fn gather_loans_in_block ( blk : & ast :: Block ,
137
+ ( this , vt ) : ( @ mut GatherLoanCtxt ,
138
+ oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
158
139
this. id_range . add ( blk. id ) ;
159
- visit :: walk_block ( v , blk, this) ;
140
+ oldvisit :: visit_block ( blk, ( this, vt ) ) ;
160
141
}
161
142
162
- fn gather_loans_in_local( v : & mut GatherLoanVisitor ,
163
- local : @ast :: Local ,
164
- this : @mut GatherLoanCtxt ) {
143
+ fn gather_loans_in_local ( local : @ast :: Local ,
144
+ ( this , vt ) : ( @ mut GatherLoanCtxt ,
145
+ oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
165
146
match local. init {
166
147
None => {
167
148
// Variable declarations without initializers are considered "moves":
@@ -192,13 +173,12 @@ fn gather_loans_in_local(v: &mut GatherLoanVisitor,
192
173
}
193
174
}
194
175
195
- visit :: walk_local ( v , local, this) ;
176
+ oldvisit :: visit_local ( local, ( this, vt ) ) ;
196
177
}
197
178
198
-
199
- fn gather_loans_in_expr( v: & mut GatherLoanVisitor ,
200
- ex: @ast:: expr,
201
- this: @mut GatherLoanCtxt ) {
179
+ fn gather_loans_in_expr( ex: @ast:: expr,
180
+ ( this, vt) : ( @mut GatherLoanCtxt ,
181
+ oldvisit:: vt < @mut GatherLoanCtxt > ) ) {
202
182
let bccx = this. bccx;
203
183
let tcx = bccx. tcx;
204
184
@@ -238,7 +218,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
238
218
// for the lifetime `scope_r` of the resulting ptr:
239
219
let scope_r = ty_region( tcx, ex. span, ty:: expr_ty( tcx, ex) ) ;
240
220
this. guarantee_valid( ex. id, ex. span, base_cmt, mutbl, scope_r) ;
241
- visit :: walk_expr ( v , ex, this) ;
221
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
242
222
}
243
223
244
224
ast:: expr_assign( l, _) | ast:: expr_assign_op( _, _, l, _) => {
@@ -255,7 +235,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
255
235
// with moves etc, just ignore.
256
236
}
257
237
}
258
- visit :: walk_expr ( v , ex, this) ;
238
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
259
239
}
260
240
261
241
ast:: expr_match( ex_v, ref arms) => {
@@ -265,7 +245,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
265
245
this. gather_pat( cmt, * pat, Some( ( arm. body. id, ex. id) ) ) ;
266
246
}
267
247
}
268
- visit :: walk_expr ( v , ex, this) ;
248
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
269
249
}
270
250
271
251
ast:: expr_index( _, _, arg) |
@@ -279,36 +259,36 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
279
259
let scope_r = ty:: re_scope ( ex. id ) ;
280
260
let arg_cmt = this. bccx . cat_expr ( arg) ;
281
261
this. guarantee_valid ( arg. id , arg. span , arg_cmt, m_imm, scope_r) ;
282
- visit :: walk_expr ( v , ex, this) ;
262
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
283
263
}
284
264
285
265
// see explanation attached to the `root_ub` field:
286
266
ast:: expr_while( cond, ref body) => {
287
267
// during the condition, can only root for the condition
288
268
this. push_repeating_id ( cond. id ) ;
289
- v . visit_expr ( cond, this) ;
269
+ ( vt . visit_expr ) ( cond, ( this, vt ) ) ;
290
270
this. pop_repeating_id ( cond. id ) ;
291
271
292
272
// during body, can only root for the body
293
273
this. push_repeating_id ( body. id ) ;
294
- v . visit_block ( body, this) ;
274
+ ( vt . visit_block ) ( body, ( this, vt ) ) ;
295
275
this. pop_repeating_id ( body. id ) ;
296
276
}
297
277
298
278
// see explanation attached to the `root_ub` field:
299
279
ast:: expr_loop( ref body, _) => {
300
280
this. push_repeating_id ( body. id ) ;
301
- visit :: walk_expr ( v , ex, this) ;
281
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
302
282
this. pop_repeating_id ( body. id ) ;
303
283
}
304
284
305
285
ast:: expr_fn_block( * ) => {
306
286
gather_moves:: gather_captures ( this. bccx , this. move_data , ex) ;
307
- visit :: walk_expr ( v , ex, this) ;
287
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
308
288
}
309
289
310
290
_ => {
311
- visit :: walk_expr ( v , ex, this) ;
291
+ oldvisit :: visit_expr ( ex, ( this, vt ) ) ;
312
292
}
313
293
}
314
294
}
@@ -790,14 +770,14 @@ impl GatherLoanCtxt {
790
770
791
771
// Setting up info that preserve needs.
792
772
// This is just the most convenient place to do it.
793
- fn add_stmt_to_map ( v : & mut GatherLoanVisitor ,
794
- stmt : @ast :: stmt ,
795
- this : @mut GatherLoanCtxt ) {
773
+ fn add_stmt_to_map ( stmt : @ast :: stmt ,
774
+ ( this , vt ) : ( @ mut GatherLoanCtxt ,
775
+ oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
796
776
match stmt. node {
797
777
ast:: stmt_expr( _, id) | ast:: stmt_semi( _, id) => {
798
778
this. bccx . stmt_map . insert ( id) ;
799
779
}
800
780
_ => ( )
801
781
}
802
- visit :: walk_stmt ( v , stmt, this) ;
782
+ oldvisit :: visit_stmt ( stmt, ( this, vt ) ) ;
803
783
}
0 commit comments