mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 07:21:51 +00:00
Fix iter_structural_ty_full for resource types
The compiler would blow up when compiling a structural type containing a resource.
This commit is contained in:
parent
4642300683
commit
5adf87a2c6
@ -1649,8 +1649,7 @@ fn make_cmp_glue(cx: &@block_ctxt, lhs0: ValueRef, rhs0: ValueRef, t: &ty::t,
|
|||||||
ret rslt(cnt_cx, C_nil());
|
ret rslt(cnt_cx, C_nil());
|
||||||
}
|
}
|
||||||
if ty::type_is_structural(bcx_tcx(cx), t) {
|
if ty::type_is_structural(bcx_tcx(cx), t) {
|
||||||
r =
|
r = iter_structural_ty_full(r.bcx, lhs, rhs, t,
|
||||||
iter_structural_ty_full(r.bcx, lhs, rhs, t,
|
|
||||||
bind inner(next, false, flag, llop, _,
|
bind inner(next, false, flag, llop, _,
|
||||||
_, _, _));
|
_, _, _));
|
||||||
} else {
|
} else {
|
||||||
@ -1661,8 +1660,7 @@ fn make_cmp_glue(cx: &@block_ctxt, lhs0: ValueRef, rhs0: ValueRef, t: &ty::t,
|
|||||||
let rhs_lim = r.bcx.build.GEP(rhs_p0, ~[min_len]);
|
let rhs_lim = r.bcx.build.GEP(rhs_p0, ~[min_len]);
|
||||||
let elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
|
let elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
|
||||||
r = size_of(r.bcx, elt_ty);
|
r = size_of(r.bcx, elt_ty);
|
||||||
r =
|
r = iter_sequence_raw(r.bcx, lhs_p0, rhs_p0, rhs_lim, r.val,
|
||||||
iter_sequence_raw(r.bcx, lhs_p0, rhs_p0, rhs_lim, r.val,
|
|
||||||
bind inner(next, true, flag, llop, _, _, _,
|
bind inner(next, true, flag, llop, _, _, _,
|
||||||
elt_ty));
|
elt_ty));
|
||||||
}
|
}
|
||||||
@ -1982,12 +1980,15 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::ty_res(_, inner, tps) {
|
ty::ty_res(_, inner, tps) {
|
||||||
let inner1 = ty::substitute_type_params(bcx_tcx(cx), tps, inner);
|
let tcx = bcx_tcx(cx);
|
||||||
r = GEP_tup_like(r.bcx, t, av, ~[0, 1]);
|
let inner1 = ty::substitute_type_params(tcx, tps, inner);
|
||||||
|
let inner_t_s = ty::substitute_type_params(tcx, tps, inner);
|
||||||
|
let tup_t = ty::mk_imm_tup(tcx, ~[ty::mk_int(tcx), inner_t_s]);
|
||||||
|
r = GEP_tup_like(r.bcx, tup_t, av, ~[0, 1]);
|
||||||
let llfld_a = r.val;
|
let llfld_a = r.val;
|
||||||
r = GEP_tup_like(r.bcx, t, bv, ~[0, 1]);
|
r = GEP_tup_like(r.bcx, tup_t, bv, ~[0, 1]);
|
||||||
let llfld_b = r.val;
|
let llfld_b = r.val;
|
||||||
f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1),
|
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1),
|
||||||
load_if_immediate(r.bcx, llfld_b, inner1), inner1);
|
load_if_immediate(r.bcx, llfld_b, inner1), inner1);
|
||||||
}
|
}
|
||||||
ty::ty_tag(tid, tps) {
|
ty::ty_tag(tid, tps) {
|
||||||
@ -2059,18 +2060,12 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
|
|||||||
|
|
||||||
// Iterates through a pointer range, until the src* hits the src_lim*.
|
// Iterates through a pointer range, until the src* hits the src_lim*.
|
||||||
fn iter_sequence_raw(cx: @block_ctxt, dst: ValueRef,
|
fn iter_sequence_raw(cx: @block_ctxt, dst: ValueRef,
|
||||||
src:
|
|
||||||
|
|
||||||
// elt*
|
// elt*
|
||||||
ValueRef,
|
src: ValueRef,
|
||||||
src_lim:
|
|
||||||
|
|
||||||
// elt*
|
// elt*
|
||||||
ValueRef,
|
src_lim: ValueRef,
|
||||||
elt_sz:
|
|
||||||
|
|
||||||
// elt*
|
// elt*
|
||||||
ValueRef, f: &val_pair_fn) -> result {
|
elt_sz: ValueRef, f: &val_pair_fn) -> result {
|
||||||
let bcx = cx;
|
let bcx = cx;
|
||||||
let dst_int: ValueRef = vp2i(bcx, dst);
|
let dst_int: ValueRef = vp2i(bcx, dst);
|
||||||
let src_int: ValueRef = vp2i(bcx, src);
|
let src_int: ValueRef = vp2i(bcx, src);
|
||||||
|
19
src/test/run-pass/resource-in-struct.rs
Normal file
19
src/test/run-pass/resource-in-struct.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Ensures that putting resources inside structual types keeps
|
||||||
|
// working.
|
||||||
|
|
||||||
|
type closable = @mutable bool;
|
||||||
|
|
||||||
|
resource close_res(i: closable) {
|
||||||
|
*i = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
tag option[T] { none; some(T); }
|
||||||
|
|
||||||
|
fn sink(res: option[close_res]) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let c = @mutable true;
|
||||||
|
sink(none);
|
||||||
|
sink(some(close_res(c)));
|
||||||
|
assert !*c;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user