@@ -416,13 +416,9 @@ pub struct DetermineRpCtxt {
416
416
item_id : ast:: node_id ,
417
417
418
418
// true when we are within an item but not within a method.
419
- // see long discussion on region_is_relevant().
419
+ // see long discussion on region_is_relevant()
420
420
anon_implies_rp : bool ,
421
421
422
- // true when we are not within an &self method.
423
- // see long discussion on region_is_relevant().
424
- self_implies_rp : bool ,
425
-
426
422
// encodes the context of the current type; invariant if
427
423
// mutable, covariant otherwise
428
424
ambient_variance : region_variance ,
@@ -462,14 +458,14 @@ pub fn add_variance(+ambient_variance: region_variance,
462
458
}
463
459
464
460
pub impl DetermineRpCtxt {
465
- fn add_variance ( & self , variance : region_variance ) -> region_variance {
461
+ fn add_variance ( @ mut self , variance : region_variance ) -> region_variance {
466
462
add_variance ( self . ambient_variance , variance)
467
463
}
468
464
469
465
/// Records that item `id` is region-parameterized with the
470
466
/// variance `variance`. If `id` was already parameterized, then
471
467
/// the new variance is joined with the old variance.
472
- fn add_rp ( & mut self , id : ast:: node_id , variance : region_variance ) {
468
+ fn add_rp ( @ mut self , id : ast:: node_id , variance : region_variance ) {
473
469
assert id != 0 ;
474
470
let old_variance = self . region_paramd_items . find ( & id) ;
475
471
let joined_variance = match old_variance {
@@ -494,7 +490,7 @@ pub impl DetermineRpCtxt {
494
490
/// `from`. Put another way, it indicates that the current item
495
491
/// contains a value of type `from`, so if `from` is
496
492
/// region-parameterized, so is the current item.
497
- fn add_dep ( & mut self , from : ast:: node_id ) {
493
+ fn add_dep ( @ mut self , from : ast:: node_id ) {
498
494
debug ! ( "add dependency from %d -> %d (%s -> %s) with variance %?" ,
499
495
from, self . item_id,
500
496
ast_map:: node_id_to_str( self . ast_map, from,
@@ -519,46 +515,42 @@ pub impl DetermineRpCtxt {
519
515
}
520
516
521
517
// Determines whether a reference to a region that appears in the
522
- // AST implies that the enclosing type is region-parameterized (RP).
523
- // This point is subtle. Here are some examples to make it more
518
+ // AST implies that the enclosing type is region-parameterized.
519
+ //
520
+ // This point is subtle. Here are four examples to make it more
524
521
// concrete.
525
522
//
526
523
// 1. impl foo for &int { ... }
527
524
// 2. impl foo for &self/int { ... }
528
- // 3. impl foo for bar { fn m(@self) -> &self/int { ... } }
529
- // 4. impl foo for bar { fn m(&self) -> &self/int { ... } }
530
- // 5. impl foo for bar { fn m(&self) -> &int { ... } }
525
+ // 3. impl foo for bar { fn m() -> &self/int { ... } }
526
+ // 4. impl foo for bar { fn m() -> &int { ... } }
531
527
//
532
528
// In case 1, the anonymous region is being referenced,
533
529
// but it appears in a context where the anonymous region
534
- // resolves to self, so the impl foo is RP .
530
+ // resolves to self, so the impl foo is region-parameterized .
535
531
//
536
532
// In case 2, the self parameter is written explicitly.
537
533
//
538
- // In case 3, the method refers to the region `self`, so that
539
- // implies that the impl must be region parameterized. (If the
540
- // type bar is not region parameterized, that is an error, because
541
- // the self region is effectively unconstrained, but that is
542
- // detected elsewhere).
543
- //
544
- // In case 4, the method refers to the region `self`, but the
545
- // `self` region is bound by the `&self` receiver, and so this
546
- // does not require that `bar` be RP.
534
+ // In case 3, the method refers to self, so that implies that the
535
+ // impl must be region parameterized. (If the type bar is not
536
+ // region parameterized, that is an error, because the self region
537
+ // is effectively unconstrained, but that is detected elsewhere).
547
538
//
548
- // In case 5 , the anonymous region is referenced, but it
539
+ // In case 4 , the anonymous region is referenced, but it
549
540
// bound by the method, so it does not refer to self. This impl
550
541
// need not be region parameterized.
551
542
//
552
- // Normally, & or &self implies that the enclosing item is RP.
553
- // However, within a function, & is always bound. Within a method
554
- // with &self type, &self is also bound. We detect those last two
555
- // cases via flags (anon_implies_rp and self_implies_rp) that are
556
- // true when the anon or self region implies RP.
557
- fn region_is_relevant ( & self , r : @ast:: region ) -> bool {
543
+ // So the rules basically are: the `self` region always implies
544
+ // that the enclosing type is region parameterized. The anonymous
545
+ // region also does, unless it appears within a method, in which
546
+ // case it is bound. We handle this by setting a flag
547
+ // (anon_implies_rp) to true when we enter an item and setting
548
+ // that flag to false when we enter a method.
549
+ fn region_is_relevant ( @mut self , r : @ast:: region ) -> bool {
558
550
match r. node {
559
551
ast:: re_static => false ,
560
552
ast:: re_anon => self . anon_implies_rp ,
561
- ast:: re_self => self . self_implies_rp ,
553
+ ast:: re_self => true ,
562
554
ast:: re_named( _) => false
563
555
}
564
556
}
@@ -569,7 +561,7 @@ pub impl DetermineRpCtxt {
569
561
//
570
562
// If the region is explicitly specified, then we follows the
571
563
// normal rules.
572
- fn opt_region_is_relevant ( & self ,
564
+ fn opt_region_is_relevant ( @ mut self ,
573
565
opt_r : Option < @ast:: region > )
574
566
-> bool {
575
567
debug ! ( "opt_region_is_relevant: %? (anon_implies_rp=%b)" ,
@@ -583,23 +575,16 @@ pub impl DetermineRpCtxt {
583
575
fn with ( @mut self ,
584
576
item_id : ast:: node_id ,
585
577
anon_implies_rp : bool ,
586
- self_implies_rp : bool ,
587
578
f : & fn ( ) ) {
588
579
let old_item_id = self . item_id ;
589
580
let old_anon_implies_rp = self . anon_implies_rp ;
590
- let old_self_implies_rp = self . self_implies_rp ;
591
581
self . item_id = item_id;
592
582
self . anon_implies_rp = anon_implies_rp;
593
- self . self_implies_rp = self_implies_rp;
594
- debug ! ( "with_item_id(%d, %b, %b)" ,
595
- item_id,
596
- anon_implies_rp,
597
- self_implies_rp) ;
583
+ debug ! ( "with_item_id(%d, %b)" , item_id, anon_implies_rp) ;
598
584
let _i = :: util:: common:: indenter ( ) ;
599
585
f ( ) ;
600
586
self . item_id = old_item_id;
601
587
self . anon_implies_rp = old_anon_implies_rp;
602
- self . self_implies_rp = old_self_implies_rp;
603
588
}
604
589
605
590
fn with_ambient_variance ( @mut self , variance : region_variance , f : & fn ( ) ) {
@@ -613,7 +598,7 @@ pub impl DetermineRpCtxt {
613
598
pub fn determine_rp_in_item ( item : @ast:: item ,
614
599
& & cx: @mut DetermineRpCtxt ,
615
600
visitor : visit:: vt < @mut DetermineRpCtxt > ) {
616
- do cx. with ( item. id , true , true ) {
601
+ do cx. with ( item. id , true ) {
617
602
visit:: visit_item ( item, cx, visitor) ;
618
603
}
619
604
}
@@ -625,12 +610,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind,
625
610
_: ast:: node_id ,
626
611
& & cx: @mut DetermineRpCtxt ,
627
612
visitor : visit:: vt < @mut DetermineRpCtxt > ) {
628
- let self_implies_rp = match fk {
629
- & visit:: fk_method( _, _, m) => !m. self_ty . node . is_borrowed ( ) ,
630
- _ => true
631
- } ;
632
-
633
- do cx. with ( cx. item_id , false , self_implies_rp) {
613
+ do cx. with ( cx. item_id , false ) {
634
614
do cx. with_ambient_variance ( rv_contravariant) {
635
615
for decl. inputs. each |a| {
636
616
( visitor. visit_ty ) ( a. ty , cx, visitor) ;
@@ -646,7 +626,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind,
646
626
pub fn determine_rp_in_ty_method ( ty_m : & ast:: ty_method ,
647
627
& & cx: @mut DetermineRpCtxt ,
648
628
visitor : visit:: vt < @mut DetermineRpCtxt > ) {
649
- do cx. with ( cx. item_id , false , !ty_m . self_ty . node . is_borrowed ( ) ) {
629
+ do cx. with ( cx. item_id , false ) {
650
630
visit:: visit_ty_method ( ty_m, cx, visitor) ;
651
631
}
652
632
}
@@ -755,7 +735,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
755
735
ast:: ty_bare_fn( @ast:: TyBareFn { decl : ref decl, _} ) => {
756
736
// fn() binds the & region, so do not consider &T types that
757
737
// appear *inside* a fn() type to affect the enclosing item:
758
- do cx. with ( cx. item_id , false , true ) {
738
+ do cx. with ( cx. item_id , false ) {
759
739
// parameters are contravariant
760
740
do cx. with_ambient_variance ( rv_contravariant) {
761
741
for decl. inputs. each |a| {
@@ -816,7 +796,6 @@ pub fn determine_rp_in_crate(sess: Session,
816
796
worklist : ~[ ] ,
817
797
item_id : 0 ,
818
798
anon_implies_rp : false ,
819
- self_implies_rp : true ,
820
799
ambient_variance : rv_covariant
821
800
} ;
822
801
0 commit comments