@@ -48,10 +48,7 @@ use syntax::visit;
48
48
49
49
pub struct Rcx {
50
50
fcx : @mut FnCtxt ,
51
- errors_reported : uint ,
52
-
53
- // id of innermost fn or loop
54
- repeating_scope : ast:: node_id ,
51
+ errors_reported : uint
55
52
}
56
53
57
54
pub type rvt = visit:: vt < @mut Rcx > ;
@@ -81,12 +78,6 @@ impl Rcx {
81
78
self . fcx . ccx . tcx
82
79
}
83
80
84
- pub fn set_repeating_scope ( & mut self , scope : ast:: node_id ) -> ast:: node_id {
85
- let old_scope = self . repeating_scope ;
86
- self . repeating_scope = scope;
87
- old_scope
88
- }
89
-
90
81
pub fn resolve_type ( & mut self , unresolved_ty : ty:: t ) -> ty:: t {
91
82
/*!
92
83
* Try to resolve the type for the given node, returning
@@ -143,8 +134,7 @@ impl Rcx {
143
134
}
144
135
145
136
pub fn regionck_expr ( fcx : @mut FnCtxt , e : @ast:: expr ) {
146
- let rcx = @mut Rcx { fcx : fcx, errors_reported : 0 ,
147
- repeating_scope : e. id } ;
137
+ let rcx = @mut Rcx { fcx : fcx, errors_reported : 0 } ;
148
138
if fcx. err_count_since_creation ( ) == 0 {
149
139
// regionck assumes typeck succeeded
150
140
let v = regionck_visitor ( ) ;
@@ -154,8 +144,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
154
144
}
155
145
156
146
pub fn regionck_fn ( fcx : @mut FnCtxt , blk : & ast:: blk ) {
157
- let rcx = @mut Rcx { fcx : fcx, errors_reported : 0 ,
158
- repeating_scope : blk. node . id } ;
147
+ let rcx = @mut Rcx { fcx : fcx, errors_reported : 0 } ;
159
148
if fcx. err_count_since_creation ( ) == 0 {
160
149
// regionck assumes typeck succeeded
161
150
let v = regionck_visitor ( ) ;
@@ -242,8 +231,7 @@ fn constrain_bindings_in_pat(pat: @ast::pat, rcx: @mut Rcx) {
242
231
}
243
232
244
233
fn visit_expr ( expr : @ast:: expr , ( rcx, v) : ( @mut Rcx , rvt ) ) {
245
- debug ! ( "regionck::visit_expr(e=%s, repeating_scope=%?)" ,
246
- expr. repr( rcx. fcx. tcx( ) ) , rcx. repeating_scope) ;
234
+ debug ! ( "regionck::visit_expr(e=?)" ) ;
247
235
248
236
let has_method_map = rcx. fcx . inh . method_map . contains_key ( & expr. id ) ;
249
237
@@ -286,9 +274,6 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
286
274
}
287
275
}
288
276
}
289
- ast:: expr_loop ( ref body, _) => {
290
- tcx. region_maps . record_cleanup_scope ( body. node . id ) ;
291
- }
292
277
ast:: expr_while ( cond, ref body) => {
293
278
tcx. region_maps . record_cleanup_scope ( cond. id ) ;
294
279
tcx. region_maps . record_cleanup_scope ( body. node . id ) ;
@@ -328,14 +313,10 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
328
313
ast : : expr_call( callee, ref args, _) => {
329
314
constrain_callee( rcx, callee. id, expr, callee) ;
330
315
constrain_call( rcx, callee. id, expr, None , * args, false ) ;
331
-
332
- visit:: visit_expr( expr, ( rcx, v) ) ;
333
316
}
334
317
335
318
ast:: expr_method_call( callee_id, arg0, _, _, ref args, _) => {
336
319
constrain_call( rcx, callee_id, expr, Some ( arg0) , * args, false ) ;
337
-
338
- visit:: visit_expr( expr, ( rcx, v) ) ;
339
320
}
340
321
341
322
ast:: expr_index( callee_id, lhs, rhs) |
@@ -346,31 +327,23 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
346
327
// implicit "by ref" sort of passing style here. This
347
328
// should be converted to an adjustment!
348
329
constrain_call( rcx, callee_id, expr, Some ( lhs) , [ rhs] , true ) ;
349
-
350
- visit:: visit_expr( expr, ( rcx, v) ) ;
351
330
}
352
331
353
332
ast:: expr_unary( callee_id, _, lhs) if has_method_map => {
354
333
// As above.
355
334
constrain_call( rcx, callee_id, expr, Some ( lhs) , [ ] , true ) ;
356
-
357
- visit:: visit_expr( expr, ( rcx, v) ) ;
358
335
}
359
336
360
337
ast:: expr_unary( _, ast:: deref, base) => {
361
338
// For *a, the lifetime of a must enclose the deref
362
339
let base_ty = rcx. resolve_node_type( base. id) ;
363
340
constrain_derefs( rcx, expr, 1 , base_ty) ;
364
-
365
- visit:: visit_expr( expr, ( rcx, v) ) ;
366
341
}
367
342
368
343
ast:: expr_index( _, vec_expr, _) => {
369
344
// For a[b], the lifetime of a must enclose the deref
370
345
let vec_type = rcx. resolve_expr_type_adjusted( vec_expr) ;
371
346
constrain_index( rcx, expr, vec_type) ;
372
-
373
- visit:: visit_expr( expr, ( rcx, v) ) ;
374
347
}
375
348
376
349
ast:: expr_cast( source, _) => {
@@ -399,8 +372,6 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
399
372
}
400
373
_ => ( )
401
374
}
402
-
403
- visit:: visit_expr( expr, ( rcx, v) ) ;
404
375
}
405
376
406
377
ast:: expr_addr_of( _, base) => {
@@ -416,87 +387,29 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
416
387
let ty0 = rcx. resolve_node_type( expr. id) ;
417
388
constrain_regions_in_type( rcx, ty:: re_scope( expr. id) ,
418
389
infer:: AddrOf ( expr. span) , ty0) ;
419
- visit:: visit_expr ( expr, ( rcx, v) ) ;
420
390
}
421
391
422
392
ast:: expr_match( discr, ref arms) => {
423
393
guarantor:: for_match( rcx, discr, * arms) ;
424
-
425
- visit:: visit_expr ( expr, ( rcx, v) ) ;
426
- }
427
-
428
- ast:: expr_loop_body ( subexpr) => {
429
- check_expr_fn_block ( rcx, subexpr, v, true ) ;
430
394
}
431
395
432
396
ast:: expr_fn_block( * ) => {
433
- check_expr_fn_block ( rcx, expr, v, false ) ;
434
- }
435
-
436
- ast:: expr_loop ( ref body, _) => {
437
- let repeating_scope = rcx. set_repeating_scope ( body. node . id ) ;
438
- visit:: visit_expr ( expr, ( rcx, v) ) ;
439
- rcx. set_repeating_scope ( repeating_scope) ;
440
- }
441
-
442
- ast:: expr_while ( cond, ref body) => {
443
- let repeating_scope = rcx. set_repeating_scope ( cond. id ) ;
444
- ( v. visit_expr ) ( cond, ( rcx, v) ) ;
445
-
446
- rcx. set_repeating_scope ( body. node . id ) ;
447
- ( v. visit_block ) ( body, ( rcx, v) ) ;
448
-
449
- rcx. set_repeating_scope ( repeating_scope) ;
450
- }
451
-
452
- _ => {
453
- visit:: visit_expr ( expr, ( rcx, v) ) ;
454
- }
455
- }
456
- }
457
-
458
- fn check_expr_fn_block( rcx: @mut Rcx ,
459
- expr: @ast:: expr,
460
- v: rvt,
461
- is_loop_body: bool ) {
462
- let tcx = rcx. fcx . tcx ( ) ;
463
- match expr. node {
464
- ast:: expr_fn_block( _, ref body) => {
397
+ // The lifetime of a block fn must not outlive the variables
398
+ // it closes over
465
399
let function_type = rcx. resolve_node_type ( expr. id ) ;
466
400
match ty:: get ( function_type) . sty {
467
- ty:: ty_closure(
468
- ty:: ClosureTy {
469
- sigil : ast:: BorrowedSigil , region : region, _} ) => {
470
- if get_freevars ( tcx, expr. id ) . is_empty ( ) && !is_loop_body {
471
- // No free variables means that the environment
472
- // will be NULL at runtime and hence the closure
473
- // has static lifetime.
474
- } else {
475
- // Otherwise, the closure must not outlive the
476
- // variables it closes over, nor can it
477
- // outlive the innermost repeating scope
478
- // (since otherwise that would require
479
- // infinite stack).
480
- constrain_free_variables ( rcx, region, expr) ;
481
- let repeating_scope = ty:: re_scope ( rcx. repeating_scope ) ;
482
- rcx. fcx . mk_subr ( true , infer:: InfStackClosure ( expr. span ) ,
483
- region, repeating_scope) ;
484
- }
401
+ ty:: ty_closure( ty:: ClosureTy { sigil : ast:: BorrowedSigil ,
402
+ region : region, _} ) => {
403
+ constrain_free_variables ( rcx, region, expr) ;
485
404
}
486
405
_ => ( )
487
406
}
488
-
489
- let repeating_scope = rcx. set_repeating_scope ( body. node . id ) ;
490
- visit:: visit_expr ( expr, ( rcx, v) ) ;
491
- rcx. set_repeating_scope ( repeating_scope) ;
492
407
}
493
408
494
- _ => {
495
- tcx. sess . span_bug (
496
- expr. span ,
497
- "Expected expr_fn_block" ) ;
498
- }
409
+ _ => ( )
499
410
}
411
+
412
+ visit:: visit_expr ( expr, ( rcx, v) ) ;
500
413
}
501
414
502
415
fn constrain_callee ( rcx : @mut Rcx ,
0 commit comments