@@ -835,6 +835,18 @@ fn fixup_self_in_method_ty(cx: ty::ctxt, mty: ty::t, m_substs: [ty::t],
835
835
} else { mty }
836
836
}
837
837
838
+ // Mangles an iface method ty to instantiate its `self` region.
839
+ fn fixup_self_region_in_method_ty ( fcx : @fn_ctxt , mty : ty:: t ,
840
+ self_expr : @ast:: expr ) -> ty:: t {
841
+ let self_region = region_of ( fcx, self_expr) ;
842
+ ty:: fold_ty ( fcx. ccx . tcx , ty:: fm_rptr ( { |r|
843
+ alt r {
844
+ ty : : re_self ( _) { self_region }
845
+ _ { r }
846
+ }
847
+ } ) , mty)
848
+ }
849
+
838
850
// Item collection - a pair of bootstrap passes:
839
851
//
840
852
// (1) Collect the IDs of all type items (typedefs) and store them in a table.
@@ -1811,6 +1823,11 @@ fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id,
1811
1823
tcx, fty, substs, option:: get ( self_sub) ) ;
1812
1824
write_ty ( tcx, node_id, fty) ;
1813
1825
}
1826
+ if ty:: type_has_rptrs ( ty:: ty_fn_ret ( fty) ) {
1827
+ let fty = ty:: node_id_to_type ( tcx, node_id) ;
1828
+ fty = fixup_self_region_in_method_ty ( fcx, fty, expr) ;
1829
+ write_ty ( tcx, node_id, fty) ;
1830
+ }
1814
1831
some ( origin)
1815
1832
}
1816
1833
none { none }
@@ -1982,9 +1999,13 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
1982
1999
}
1983
2000
}
1984
2001
}
1985
- ast:: expr_field ( base, _, _) | ast:: expr_index ( base, _) {
1986
- fcx. ccx . tcx . sess . span_unimpl ( expr. span , "regions of field or " +
1987
- "index operations" ) ;
2002
+ ast:: expr_field ( base, _, _) {
2003
+ // FIXME: Insert borrowing!
2004
+ ret region_of ( fcx, base) ;
2005
+ }
2006
+ ast:: expr_index ( base, _) {
2007
+ fcx. ccx . tcx . sess . span_unimpl ( expr. span ,
2008
+ "regions of index operations" ) ;
1988
2009
}
1989
2010
ast:: expr_unary ( ast:: deref, base) {
1990
2011
let expr_ty = ty:: expr_ty ( fcx. ccx . tcx , base) ;
0 commit comments