Skip to content

Commit 4bbc13d

Browse files
committed
auto merge of #6705 : brson/rust/issue-5192, r=catamorphism
r? @catamorphism This could probably refactored to more closely mirror the code for `@objects`, but I'm not inclined to do so.
2 parents d49d0f8 + d213443 commit 4bbc13d

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/librustc/middle/trans/glue.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,23 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
546546
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
547547
}
548548
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
549-
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
550-
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
551-
552-
// Cast the vtable to a pointer to a pointer to a tydesc.
553-
let llvtable = PointerCast(bcx,
554-
llvtable,
555-
T_ptr(T_ptr(ccx.tydesc_type)));
556-
let lltydesc = Load(bcx, llvtable);
557-
call_tydesc_glue_full(bcx,
558-
lluniquevalue,
559-
lltydesc,
560-
abi::tydesc_field_free_glue,
561-
None);
562-
bcx
549+
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
550+
// Only drop the value when it is non-null
551+
do with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue))) |bcx| {
552+
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
553+
554+
// Cast the vtable to a pointer to a pointer to a tydesc.
555+
let llvtable = PointerCast(bcx,
556+
llvtable,
557+
T_ptr(T_ptr(ccx.tydesc_type)));
558+
let lltydesc = Load(bcx, llvtable);
559+
call_tydesc_glue_full(bcx,
560+
lluniquevalue,
561+
lltydesc,
562+
abi::tydesc_field_free_glue,
563+
None);
564+
bcx
565+
}
563566
}
564567
ty::ty_opaque_closure_ptr(ck) => {
565568
closure::make_opaque_cbox_drop_glue(bcx, ck, v0)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Issue #5192
12+
13+
pub trait EventLoop { }
14+
15+
pub struct UvEventLoop {
16+
uvio: int
17+
}
18+
19+
impl EventLoop for UvEventLoop { }
20+
21+
pub fn main() {
22+
let loop_: ~EventLoop = ~UvEventLoop { uvio: 0 } as ~EventLoop;
23+
let loop2_ = loop_;
24+
}

0 commit comments

Comments
 (0)