diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-03-19 18:52:18 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-03-19 18:52:18 -0700 |
| commit | bf13fb7921bae57bcb153f7842afa2959aaf47a1 (patch) | |
| tree | 62c978d2e170722f879f62cc29f60720b22c4690 /src/rustc/middle | |
| parent | b12588a197bcba39a170d78ff02a2b4f8f73ae3d (diff) | |
| download | rust-bf13fb7921bae57bcb153f7842afa2959aaf47a1.tar.gz rust-bf13fb7921bae57bcb153f7842afa2959aaf47a1.zip | |
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.
Diffstat (limited to 'src/rustc/middle')
| -rw-r--r-- | src/rustc/middle/typeck.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index be2dd9c6954..528e8fb9500 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -835,6 +835,18 @@ fn fixup_self_in_method_ty(cx: ty::ctxt, mty: ty::t, m_substs: [ty::t], } else { mty } } +// Mangles an iface method ty to instantiate its `self` region. +fn fixup_self_region_in_method_ty(fcx: @fn_ctxt, mty: ty::t, + self_expr: @ast::expr) -> ty::t { + let self_region = region_of(fcx, self_expr); + ty::fold_ty(fcx.ccx.tcx, ty::fm_rptr({|r| + alt r { + ty::re_self(_) { self_region } + _ { r } + } + }), mty) +} + // Item collection - a pair of bootstrap passes: // // (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, tcx, fty, substs, option::get(self_sub)); write_ty(tcx, node_id, fty); } + if ty::type_has_rptrs(ty::ty_fn_ret(fty)) { + let fty = ty::node_id_to_type(tcx, node_id); + fty = fixup_self_region_in_method_ty(fcx, fty, expr); + write_ty(tcx, node_id, fty); + } some(origin) } none { none } @@ -1982,9 +1999,13 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region { } } } - ast::expr_field(base, _, _) | ast::expr_index(base, _) { - fcx.ccx.tcx.sess.span_unimpl(expr.span, "regions of field or " + - "index operations"); + ast::expr_field(base, _, _) { + // FIXME: Insert borrowing! + ret region_of(fcx, base); + } + ast::expr_index(base, _) { + fcx.ccx.tcx.sess.span_unimpl(expr.span, + "regions of index operations"); } ast::expr_unary(ast::deref, base) { let expr_ty = ty::expr_ty(fcx.ccx.tcx, base); |
