Skip to content

Commit d730bb7

Browse files
committed
Make it possible to use * to dereference a resource
1 parent b3443eb commit d730bb7

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/comp/middle/alias.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,14 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
544544
auto base_t = ty::expr_ty(*cx.tcx, base);
545545
alt (ty::struct(*cx.tcx, base_t)) {
546546
case (ty::ty_box(?mt)) {
547-
vec::push(ds,
548-
rec(mut=mt.mut != ast::imm,
549-
kind=unbox,
550-
outer_t=base_t));
547+
vec::push(ds, rec(mut=mt.mut != ast::imm,
548+
kind=unbox,
549+
outer_t=base_t));
550+
}
551+
case (ty::ty_res(_, ?inner)) {
552+
vec::push(ds, rec(mut=false,
553+
kind=unbox,
554+
outer_t=base_t));
551555
}
552556
}
553557
ex = base;

src/comp/middle/trans.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,8 +4511,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
45114511
cx.build.Store(llenvblobptr, env_cell);
45124512
// log "lliterbody: " + val_str(lcx.ccx.tn, lliterbody);
45134513

4514-
r =
4515-
trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
4514+
r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
45164515
seq.id);
45174516
ret rslt(r.bcx, C_nil());
45184517
}
@@ -4993,9 +4992,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
49934992
case (ast::expr_unary(?unop, ?base)) {
49944993
assert (unop == ast::deref);
49954994
auto sub = trans_expr(cx, base);
4996-
auto val =
4997-
sub.bcx.build.GEP(sub.val,
4998-
[C_int(0), C_int(abi::box_rc_field_body)]);
4995+
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
4996+
auto offset = alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
4997+
case (ty::ty_box(_)) { abi::box_rc_field_body }
4998+
case (ty::ty_res(_, _)) { 1 }
4999+
};
5000+
auto val = sub.bcx.build.GEP(sub.val, [C_int(0), C_int(offset)]);
49995001
ret lval_mem(sub.bcx, val);
50005002
}
50015003
case (ast::expr_self_method(?ident)) {

src/comp/middle/typeck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
15261526
case (ast::deref) {
15271527
alt (structure_of(fcx, expr.span, oper_t)) {
15281528
case (ty::ty_box(?inner)) { oper_t = inner.ty; }
1529+
case (ty::ty_res(_, ?inner)) { oper_t = inner; }
15291530
case (_) {
15301531
auto s = "dereferencing non-box type: " +
15311532
ty_to_str(fcx.ccx.tcx, oper_t);

0 commit comments

Comments
 (0)