@@ -54,43 +54,38 @@ use syntax::visit::Visitor;
54
54
pub struct Context {
55
55
tcx : ty:: ctxt ,
56
56
method_map : typeck:: method_map ,
57
- current_item : NodeId
58
57
}
59
58
60
- struct KindAnalysisVisitor ;
59
+ impl Visitor < ( ) > for Context {
61
60
62
- impl Visitor < Context > for KindAnalysisVisitor {
63
-
64
- fn visit_expr ( & mut self , ex : @Expr , e : Context ) {
65
- check_expr ( self , ex, e) ;
61
+ fn visit_expr ( & mut self , ex : @Expr , _: ( ) ) {
62
+ check_expr ( self , ex) ;
66
63
}
67
64
68
- fn visit_fn ( & mut self , fk : & visit:: fn_kind , fd : & fn_decl , b : & Block , s : Span , n : NodeId , e : Context ) {
69
- check_fn ( self , fk, fd, b, s, n, e ) ;
65
+ fn visit_fn ( & mut self , fk : & visit:: fn_kind , fd : & fn_decl , b : & Block , s : Span , n : NodeId , _ : ( ) ) {
66
+ check_fn ( self , fk, fd, b, s, n) ;
70
67
}
71
68
72
- fn visit_ty ( & mut self , t : & Ty , e : Context ) {
73
- check_ty ( self , t, e ) ;
69
+ fn visit_ty ( & mut self , t : & Ty , _ : ( ) ) {
70
+ check_ty ( self , t) ;
74
71
}
75
- fn visit_item ( & mut self , i: @item, e : Context ) {
76
- check_item ( self , i, e ) ;
72
+ fn visit_item ( & mut self , i: @item, _ : ( ) ) {
73
+ check_item ( self , i) ;
77
74
}
78
75
}
79
76
80
77
pub fn check_crate ( tcx : ty:: ctxt ,
81
78
method_map : typeck:: method_map ,
82
79
crate : & Crate ) {
83
- let ctx = Context {
80
+ let mut ctx = Context {
84
81
tcx : tcx,
85
82
method_map : method_map,
86
- current_item : -1
87
83
} ;
88
- let mut visit = KindAnalysisVisitor ;
89
- visit:: walk_crate ( & mut visit, crate , ctx) ;
84
+ visit:: walk_crate ( & mut ctx, crate , ( ) ) ;
90
85
tcx. sess . abort_if_errors ( ) ;
91
86
}
92
87
93
- fn check_struct_safe_for_destructor ( cx : Context ,
88
+ fn check_struct_safe_for_destructor ( cx : & mut Context ,
94
89
span : Span ,
95
90
struct_did : DefId ) {
96
91
let struct_tpt = ty:: lookup_item_type ( cx. tcx , struct_did) ;
@@ -120,7 +115,7 @@ fn check_struct_safe_for_destructor(cx: Context,
120
115
}
121
116
}
122
117
123
- fn check_impl_of_trait( cx : Context , it: @item, trait_ref : & trait_ref , self_type : & Ty ) {
118
+ fn check_impl_of_trait( cx : & mut Context , it: @item, trait_ref : & trait_ref , self_type : & Ty ) {
124
119
let ast_trait_def = cx. tcx . def_map . find ( & trait_ref. ref_id )
125
120
. expect ( "trait ref not in def map!" ) ;
126
121
let trait_def_id = ast_util:: def_id_of_def ( * ast_trait_def) ;
@@ -156,7 +151,7 @@ fn check_impl_of_trait(cx: Context, it: @item, trait_ref: &trait_ref, self_type:
156
151
}
157
152
}
158
153
159
- fn check_item ( visitor : & mut KindAnalysisVisitor , item: @item, cx : Context ) {
154
+ fn check_item ( cx : & mut Context , item: @item) {
160
155
if !attr:: contains_name ( item. attrs , "unsafe_destructor" ) {
161
156
match item. node {
162
157
item_impl( _, Some ( ref trait_ref) , ref self_type, _) => {
@@ -166,16 +161,15 @@ fn check_item(visitor: &mut KindAnalysisVisitor, item: @item, cx: Context) {
166
161
}
167
162
}
168
163
169
- let cx = Context { current_item : item. id , ..cx } ;
170
- visit:: walk_item ( visitor, item, cx) ;
164
+ visit:: walk_item ( cx, item, ( ) ) ;
171
165
}
172
166
173
167
// Yields the appropriate function to check the kind of closed over
174
168
// variables. `id` is the NodeId for some expression that creates the
175
169
// closure.
176
- fn with_appropriate_checker ( cx : Context , id : NodeId ,
177
- b : & fn ( checker : & fn ( Context , @freevar_entry ) ) ) {
178
- fn check_for_uniq ( cx : Context , fv : & freevar_entry , bounds : ty:: BuiltinBounds ) {
170
+ fn with_appropriate_checker ( cx : & Context , id : NodeId ,
171
+ b : & fn ( checker : & fn ( & Context , @freevar_entry ) ) ) {
172
+ fn check_for_uniq ( cx : & Context , fv : & freevar_entry , bounds : ty:: BuiltinBounds ) {
179
173
// all captured data must be owned, regardless of whether it is
180
174
// moved in or copied in.
181
175
let id = ast_util:: def_id_of_def ( fv. def ) . node ;
@@ -187,7 +181,7 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
187
181
check_freevar_bounds ( cx, fv. span , var_t, bounds, None ) ;
188
182
}
189
183
190
- fn check_for_box ( cx : Context , fv : & freevar_entry , bounds : ty:: BuiltinBounds ) {
184
+ fn check_for_box ( cx : & Context , fv : & freevar_entry , bounds : ty:: BuiltinBounds ) {
191
185
// all captured data must be owned
192
186
let id = ast_util:: def_id_of_def ( fv. def ) . node ;
193
187
let var_t = ty:: node_id_to_type ( cx. tcx , id) ;
@@ -198,7 +192,7 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
198
192
check_freevar_bounds ( cx, fv. span , var_t, bounds, None ) ;
199
193
}
200
194
201
- fn check_for_block ( cx : Context , fv : & freevar_entry ,
195
+ fn check_for_block ( cx : & Context , fv : & freevar_entry ,
202
196
bounds : ty:: BuiltinBounds , region : ty:: Region ) {
203
197
let id = ast_util:: def_id_of_def ( fv. def ) . node ;
204
198
let var_t = ty:: node_id_to_type ( cx. tcx , id) ;
@@ -209,7 +203,7 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
209
203
bounds, Some ( var_t) ) ;
210
204
}
211
205
212
- fn check_for_bare ( cx : Context , fv : @freevar_entry ) {
206
+ fn check_for_bare ( cx : & Context , fv : @freevar_entry ) {
213
207
cx. tcx . sess . span_err (
214
208
fv. span ,
215
209
"can't capture dynamic environment in a fn item; \
@@ -252,13 +246,12 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
252
246
// Check that the free variables used in a shared/sendable closure conform
253
247
// to the copy/move kind bounds. Then recursively check the function body.
254
248
fn check_fn(
255
- v : & mut KindAnalysisVisitor ,
249
+ cx : & mut Context ,
256
250
fk : & visit:: fn_kind ,
257
251
decl : & fn_decl ,
258
252
body : & Block ,
259
253
sp : Span ,
260
- fn_id : NodeId ,
261
- cx : Context ) {
254
+ fn_id : NodeId ) {
262
255
263
256
// Check kinds on free variables:
264
257
do with_appropriate_checker ( cx, fn_id) |chk| {
@@ -268,10 +261,10 @@ fn check_fn(
268
261
}
269
262
}
270
263
271
- visit:: walk_fn ( v , fk, decl, body, sp, fn_id, cx ) ;
264
+ visit:: walk_fn ( cx , fk, decl, body, sp, fn_id, ( ) ) ;
272
265
}
273
266
274
- pub fn check_expr ( v : & mut KindAnalysisVisitor , e : @Expr , cx : Context ) {
267
+ pub fn check_expr ( cx : & mut Context , e : @Expr ) {
275
268
debug ! ( "kind::check_expr(%s)" , expr_to_str( e, cx. tcx. sess. intr( ) ) ) ;
276
269
277
270
// Handle any kind bounds on type parameters
@@ -336,10 +329,10 @@ pub fn check_expr(v: &mut KindAnalysisVisitor, e: @Expr, cx: Context) {
336
329
}
337
330
_ => { }
338
331
}
339
- visit:: walk_expr ( v , e, cx ) ;
332
+ visit:: walk_expr ( cx , e, ( ) ) ;
340
333
}
341
334
342
- fn check_ty ( v : & mut KindAnalysisVisitor , aty : & Ty , cx : Context ) {
335
+ fn check_ty ( cx : & mut Context , aty : & Ty ) {
343
336
match aty. node {
344
337
ty_path( _, _, id) => {
345
338
let r = cx. tcx . node_type_substs . find ( & id) ;
@@ -354,11 +347,11 @@ fn check_ty(v: &mut KindAnalysisVisitor, aty: &Ty, cx: Context) {
354
347
}
355
348
_ => { }
356
349
}
357
- visit:: walk_ty ( v , aty, cx ) ;
350
+ visit:: walk_ty ( cx , aty, ( ) ) ;
358
351
}
359
352
360
353
// Calls "any_missing" if any bounds were missing.
361
- pub fn check_builtin_bounds ( cx : Context , ty : ty:: t , bounds : ty:: BuiltinBounds ,
354
+ pub fn check_builtin_bounds ( cx : & Context , ty : ty:: t , bounds : ty:: BuiltinBounds ,
362
355
any_missing : & fn ( ty:: BuiltinBounds ) )
363
356
{
364
357
let kind = ty:: type_contents ( cx. tcx , ty) ;
@@ -373,7 +366,7 @@ pub fn check_builtin_bounds(cx: Context, ty: ty::t, bounds: ty::BuiltinBounds,
373
366
}
374
367
}
375
368
376
- pub fn check_typaram_bounds ( cx : Context ,
369
+ pub fn check_typaram_bounds ( cx : & Context ,
377
370
_type_parameter_id : NodeId ,
378
371
sp : Span ,
379
372
ty : ty:: t ,
@@ -389,7 +382,7 @@ pub fn check_typaram_bounds(cx: Context,
389
382
}
390
383
}
391
384
392
- pub fn check_freevar_bounds ( cx : Context , sp : Span , ty : ty:: t ,
385
+ pub fn check_freevar_bounds ( cx : & Context , sp : Span , ty : ty:: t ,
393
386
bounds : ty:: BuiltinBounds , referenced_ty : Option < ty:: t > )
394
387
{
395
388
do check_builtin_bounds ( cx, ty, bounds) |missing| {
@@ -412,7 +405,7 @@ pub fn check_freevar_bounds(cx: Context, sp: Span, ty: ty::t,
412
405
}
413
406
}
414
407
415
- pub fn check_trait_cast_bounds ( cx : Context , sp : Span , ty : ty:: t ,
408
+ pub fn check_trait_cast_bounds ( cx : & Context , sp : Span , ty : ty:: t ,
416
409
bounds : ty:: BuiltinBounds ) {
417
410
do check_builtin_bounds ( cx, ty, bounds) |missing| {
418
411
cx. tcx . sess . span_err ( sp,
@@ -423,7 +416,7 @@ pub fn check_trait_cast_bounds(cx: Context, sp: Span, ty: ty::t,
423
416
}
424
417
}
425
418
426
- fn is_nullary_variant ( cx : Context , ex : @Expr ) -> bool {
419
+ fn is_nullary_variant ( cx : & Context , ex : @Expr ) -> bool {
427
420
match ex. node {
428
421
ExprPath ( _) => {
429
422
match cx. tcx . def_map . get_copy ( & ex. id ) {
@@ -437,7 +430,7 @@ fn is_nullary_variant(cx: Context, ex: @Expr) -> bool {
437
430
}
438
431
}
439
432
440
- fn check_imm_free_var ( cx : Context , def : Def , sp : Span ) {
433
+ fn check_imm_free_var ( cx : & Context , def : Def , sp : Span ) {
441
434
match def {
442
435
DefLocal ( _, is_mutbl) => {
443
436
if is_mutbl {
@@ -457,7 +450,7 @@ fn check_imm_free_var(cx: Context, def: Def, sp: Span) {
457
450
}
458
451
}
459
452
460
- fn check_copy ( cx : Context , ty : ty:: t , sp : Span , reason : & str ) {
453
+ fn check_copy ( cx : & Context , ty : ty:: t , sp : Span , reason : & str ) {
461
454
debug ! ( "type_contents(%s)=%s" ,
462
455
ty_to_str( cx. tcx, ty) ,
463
456
ty:: type_contents( cx. tcx, ty) . to_str( ) ) ;
@@ -469,7 +462,7 @@ fn check_copy(cx: Context, ty: ty::t, sp: Span, reason: &str) {
469
462
}
470
463
}
471
464
472
- pub fn check_send ( cx : Context , ty : ty:: t , sp : Span ) -> bool {
465
+ pub fn check_send ( cx : & Context , ty : ty:: t , sp : Span ) -> bool {
473
466
if !ty:: type_is_sendable ( cx. tcx , ty) {
474
467
cx. tcx . sess . span_err (
475
468
sp, fmt ! ( "value has non-sendable type `%s`" ,
@@ -525,7 +518,7 @@ pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
525
518
///
526
519
/// FIXME(#5723)---This code should probably move into regionck.
527
520
pub fn check_cast_for_escaping_regions (
528
- cx : Context ,
521
+ cx : & Context ,
529
522
source : & Expr ,
530
523
target : & Expr )
531
524
{
@@ -601,7 +594,7 @@ pub fn check_cast_for_escaping_regions(
601
594
}
602
595
}
603
596
604
- fn is_subregion_of ( cx : Context , r_sub : ty:: Region , r_sup : ty:: Region ) -> bool {
597
+ fn is_subregion_of ( cx : & Context , r_sub : ty:: Region , r_sup : ty:: Region ) -> bool {
605
598
cx. tcx . region_maps . is_subregion_of ( r_sub, r_sup)
606
599
}
607
600
}
0 commit comments