@@ -434,7 +434,11 @@ type determine_rp_ctxt = @{
434
434
dep_map : dep_map ,
435
435
worklist : dvec < ast:: node_id > ,
436
436
437
+ // the innermost enclosing item id
437
438
mut item_id : ast:: node_id ,
439
+
440
+ // true when we are within an item but not within a method.
441
+ // see long discussion on region_is_relevant()
438
442
mut anon_implies_rp : bool
439
443
} ;
440
444
@@ -466,6 +470,38 @@ impl methods for determine_rp_ctxt {
466
470
if !vec. contains ( to) { vec. push ( to) ; }
467
471
}
468
472
473
+ // Determines whether a reference to a region that appears in the
474
+ // AST implies that the enclosing type is region-parameterized.
475
+ //
476
+ // This point is subtle. Here are four examples to make it more
477
+ // concrete.
478
+ //
479
+ // 1. impl foo for &int { ... }
480
+ // 2. impl foo for &self/int { ... }
481
+ // 3. impl foo for bar { fn m() -> &self/int { ... } }
482
+ // 4. impl foo for bar { fn m() -> &int { ... } }
483
+ //
484
+ // In case 1, the anonymous region is being referenced,
485
+ // but it appears in a context where the anonymous region
486
+ // resolves to self, so the impl foo is region-parameterized.
487
+ //
488
+ // In case 2, the self parameter is written explicitly.
489
+ //
490
+ // In case 3, the method refers to self, so that implies that the
491
+ // impl must be region parameterized. (If the type bar is not
492
+ // region parameterized, that is an error, because the self region
493
+ // is effectively unconstrained, but that is detected elsewhere).
494
+ //
495
+ // In case 4, the anonymous region is referenced, but it
496
+ // bound by the method, so it does not refer to self. This impl
497
+ // need not be region parameterized.
498
+ //
499
+ // So the rules basically are: the `self` region always implies
500
+ // that the enclosing type is region parameterized. The anonymous
501
+ // region also does, unless it appears within a method, in which
502
+ // case it is bound. We handle this by setting a flag
503
+ // (anon_implies_rp) to true when we enter an item and setting
504
+ // that flag to false when we enter a method.
469
505
fn region_is_relevant ( r : @ast:: region ) -> bool {
470
506
alt r. node {
471
507
ast:: re_anon { self. anon_implies_rp }
0 commit comments