@@ -494,8 +494,8 @@ pub mod guarantor {
494
494
* inferencer would not know of this dependency and thus it might
495
495
* infer the lifetime of L2 to be greater than L1 (issue #3148).
496
496
*
497
- * There are a number of troublesome scenarios in the test
498
- * `region-dependent-addr-of .rs`, but here is one example:
497
+ * There are a number of troublesome scenarios in the tests
498
+ * `region-dependent-* .rs`, but here is one example:
499
499
*
500
500
* struct Foo { i: int }
501
501
* struct Bar { foo: Foo }
@@ -583,8 +583,35 @@ pub mod guarantor {
583
583
let mut expr_ct = categorize_unadjusted( rcx, expr) ;
584
584
expr_ct = apply_autoderefs(
585
585
rcx, expr, autoderefs, expr_ct) ;
586
- for expr_ct. cat. guarantor. each |g| {
587
- infallibly_mk_subr( rcx, true , expr. span, autoref. region, * g) ;
586
+
587
+ match autoref. kind {
588
+ ty:: AutoPtr => {
589
+ // In this case, we are implicitly adding an `&`.
590
+ maybe_make_subregion( rcx, expr, autoref. region,
591
+ expr_ct. cat. guarantor) ;
592
+ }
593
+
594
+ ty:: AutoBorrowVec |
595
+ ty:: AutoBorrowVecRef |
596
+ ty:: AutoBorrowFn => {
597
+ // In each of these cases, what is being borrowed is
598
+ // not the (autoderef'd) expr itself but rather the
599
+ // contents of the autoderef'd expression (i.e., what
600
+ // the pointer points at).
601
+ maybe_make_subregion( rcx, expr, autoref. region,
602
+ guarantor_of_deref( & expr_ct. cat) ) ;
603
+ }
604
+ }
605
+
606
+ fn maybe_make_subregion(
607
+ rcx: @mut Rcx ,
608
+ expr: @ast:: expr,
609
+ sub_region: ty:: Region ,
610
+ sup_region: Option <ty:: Region >)
611
+ {
612
+ for sup_region. each |r| {
613
+ infallibly_mk_subr( rcx, true , expr. span, sub_region, * r) ;
614
+ }
588
615
}
589
616
}
590
617
@@ -813,19 +840,31 @@ pub mod guarantor {
813
840
814
841
fn pointer_categorize( ty: ty:: t) -> PointerCategorization {
815
842
match ty:: get( ty) . sty {
816
- ty:: ty_rptr( r, _) | ty:: ty_evec( _, ty:: vstore_slice( r) ) |
843
+ ty:: ty_rptr( r, _) |
844
+ ty:: ty_evec( _, ty:: vstore_slice( r) ) |
817
845
ty:: ty_estr( ty:: vstore_slice( r) ) => {
818
846
BorrowedPointer ( r)
819
847
}
820
- ty:: ty_uniq( * ) | ty:: ty_estr( ty:: vstore_uniq) |
848
+ ty:: ty_uniq( * ) |
849
+ ty:: ty_estr( ty:: vstore_uniq) |
821
850
ty:: ty_evec( _, ty:: vstore_uniq) => {
822
851
OwnedPointer
823
852
}
824
- ty:: ty_box( * ) | ty:: ty_ptr( * ) |
853
+ ty:: ty_box( * ) |
854
+ ty:: ty_ptr( * ) |
825
855
ty:: ty_evec( _, ty:: vstore_box) |
826
856
ty:: ty_estr( ty:: vstore_box) => {
827
857
OtherPointer
828
858
}
859
+ ty:: ty_closure( ref closure_ty) => {
860
+ match closure_ty. sigil {
861
+ ast:: BorrowedSigil => BorrowedPointer ( closure_ty. region) ,
862
+ ast:: OwnedSigil => OwnedPointer ,
863
+
864
+ // NOTE This is...not quite right. Deduce a test etc.
865
+ ast:: ManagedSigil => OtherPointer ,
866
+ }
867
+ }
829
868
_ => {
830
869
NotPointer
831
870
}
0 commit comments