Skip to content

Commit bf13fb7

Browse files
committed
rustc: Fix handling of the self region in method return types. Also stub some code to allow the regions of simple field access expressions to be determined.
1 parent b12588a commit bf13fb7

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/rustc/middle/typeck.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ fn fixup_self_in_method_ty(cx: ty::ctxt, mty: ty::t, m_substs: [ty::t],
835835
} else { mty }
836836
}
837837

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+
838850
// Item collection - a pair of bootstrap passes:
839851
//
840852
// (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,
18111823
tcx, fty, substs, option::get(self_sub));
18121824
write_ty(tcx, node_id, fty);
18131825
}
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+
}
18141831
some(origin)
18151832
}
18161833
none { none }
@@ -1982,9 +1999,13 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
19821999
}
19832000
}
19842001
}
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");
19882009
}
19892010
ast::expr_unary(ast::deref, base) {
19902011
let expr_ty = ty::expr_ty(fcx.ccx.tcx, base);

0 commit comments

Comments
 (0)