Skip to content

Commit 2b45a0d

Browse files
committed
Auto merge of #27618 - dotdash:drop_fixes, r=luqmana
2 parents 542d56e + f804872 commit 2b45a0d

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

src/librustc_trans/trans/glue.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
324324

325325
pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
326326
did: ast::DefId,
327-
t: Ty<'tcx>,
328327
parent_id: ast::DefId,
329328
substs: &Substs<'tcx>)
330329
-> ValueRef {
@@ -347,11 +346,8 @@ pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
347346
let name = csearch::get_symbol(&ccx.sess().cstore, did);
348347
let class_ty = tcx.lookup_item_type(parent_id).ty.subst(tcx, substs);
349348
let llty = type_of_dtor(ccx, class_ty);
350-
let dtor_ty = ccx.tcx().mk_ctor_fn(did,
351-
&[get_drop_glue_type(ccx, t)],
352-
ccx.tcx().mk_nil());
353349
foreign::get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), &name[..], llvm::CCallConv,
354-
llty, dtor_ty)
350+
llty, ccx.tcx().mk_nil())
355351
}
356352
}
357353

@@ -366,7 +362,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
366362
debug!("trans_struct_drop t: {}", t);
367363

368364
// Find and call the actual destructor
369-
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, t, class_did, substs);
365+
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, class_did, substs);
370366

371367
// Class dtors have no explicit args, so the params should
372368
// just consist of the environment (self).

src/librustc_trans/trans/type_of.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
472472
}
473473

474474
pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type {
475-
let self_ty = type_of(ccx, self_ty).ptr_to();
476-
Type::func(&[self_ty], &Type::void(ccx))
475+
if type_is_sized(ccx.tcx(), self_ty) {
476+
Type::func(&[type_of(ccx, self_ty).ptr_to()], &Type::void(ccx))
477+
} else {
478+
Type::func(&type_of(ccx, self_ty).field_types(), &Type::void(ccx))
479+
}
477480
}

src/test/auxiliary/fat_drop.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
pub static mut DROPPED: bool = false;
12+
13+
pub struct S {
14+
_unsized: [u8]
15+
}
16+
17+
impl Drop for S {
18+
fn drop(&mut self) {
19+
unsafe {
20+
DROPPED = true;
21+
}
22+
}
23+
}

src/test/run-pass/extern_fat_drop.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
// aux-build:fat_drop.rs
12+
13+
#![feature(core_intrinsics)]
14+
15+
extern crate fat_drop;
16+
17+
fn main() {
18+
unsafe {
19+
let s: &mut fat_drop::S = std::mem::uninitialized();
20+
std::intrinsics::drop_in_place(s);
21+
assert!(fat_drop::DROPPED);
22+
}
23+
}

0 commit comments

Comments
 (0)