Skip to content

Commit a0b78e6

Browse files
committed
"Narrow scope forgives many sins." -- M. Schwern
1 parent a9b77a5 commit a0b78e6

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/comp/middle/trans.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,7 +7129,6 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
71297129
methods = anon_obj.methods,
71307130
dtor = none[@ast::method]);
71317131

7132-
let option::t[result] with_obj_val = none;
71337132
let ty::t with_obj_ty;
71347133
auto vtbl;
71357134
alt (anon_obj.with_obj) {
@@ -7152,11 +7151,6 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
71527151
additional_field_tys);
71537152
}
71547153
case (some(?e)) {
7155-
// If with_obj (the object being extended) exists, translate it.
7156-
// Translating with_obj returns a ValueRef (pointer to a 2-word
7157-
// value) wrapped in a result.
7158-
with_obj_val = some(trans_expr(bcx, e));
7159-
71607154
// TODO: What makes more sense to get the type of an expr --
71617155
// calling ty::expr_ty(ccx.tcx, e) on it or calling
71627156
// ty::node_id_to_type(ccx.tcx, id) on its id?
@@ -7327,17 +7321,22 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
73277321
i += 1;
73287322
}
73297323

7330-
// Copy a pointer to the with_obj into the object's body.
7331-
auto body_with_obj =
7332-
GEP_tup_like(bcx, body_ty, body.val,
7333-
~[0, abi::obj_body_elt_with_obj]);
7334-
bcx = body_with_obj.bcx;
7335-
alt (with_obj_val) {
7336-
case (some(?v)) {
7324+
// If there's a with_obj, copy a pointer to it into the object's body.
7325+
alt (anon_obj.with_obj) {
7326+
case (none) { }
7327+
case (some(?e)) {
7328+
// If with_obj (the object being extended) exists, translate
7329+
// it. Translating with_obj returns a ValueRef (pointer to a
7330+
// 2-word value) wrapped in a result.
7331+
let result with_obj_val = trans_expr(bcx, e);
7332+
7333+
auto body_with_obj =
7334+
GEP_tup_like(bcx, body_ty, body.val,
7335+
~[0, abi::obj_body_elt_with_obj]);
7336+
bcx = body_with_obj.bcx;
73377337
bcx = copy_val(bcx, INIT, body_with_obj.val,
7338-
v.val, with_obj_ty).bcx;
7338+
with_obj_val.val, with_obj_ty).bcx;
73397339
}
7340-
case (_) {}
73417340
}
73427341

73437342
// Store box ptr in outer pair.

0 commit comments

Comments
 (0)