mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 04:39:16 +00:00
Auto merge of #27618 - dotdash:drop_fixes, r=luqmana
This commit is contained in:
commit
2b45a0d908
@ -324,7 +324,6 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
|
||||
pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
did: ast::DefId,
|
||||
t: Ty<'tcx>,
|
||||
parent_id: ast::DefId,
|
||||
substs: &Substs<'tcx>)
|
||||
-> ValueRef {
|
||||
@ -347,11 +346,8 @@ pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
let name = csearch::get_symbol(&ccx.sess().cstore, did);
|
||||
let class_ty = tcx.lookup_item_type(parent_id).ty.subst(tcx, substs);
|
||||
let llty = type_of_dtor(ccx, class_ty);
|
||||
let dtor_ty = ccx.tcx().mk_ctor_fn(did,
|
||||
&[get_drop_glue_type(ccx, t)],
|
||||
ccx.tcx().mk_nil());
|
||||
foreign::get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), &name[..], llvm::CCallConv,
|
||||
llty, dtor_ty)
|
||||
llty, ccx.tcx().mk_nil())
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,7 +362,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
debug!("trans_struct_drop t: {}", t);
|
||||
|
||||
// Find and call the actual destructor
|
||||
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, t, class_did, substs);
|
||||
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, class_did, substs);
|
||||
|
||||
// Class dtors have no explicit args, so the params should
|
||||
// just consist of the environment (self).
|
||||
|
@ -472,6 +472,9 @@ fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type {
|
||||
let self_ty = type_of(ccx, self_ty).ptr_to();
|
||||
Type::func(&[self_ty], &Type::void(ccx))
|
||||
if type_is_sized(ccx.tcx(), self_ty) {
|
||||
Type::func(&[type_of(ccx, self_ty).ptr_to()], &Type::void(ccx))
|
||||
} else {
|
||||
Type::func(&type_of(ccx, self_ty).field_types(), &Type::void(ccx))
|
||||
}
|
||||
}
|
||||
|
23
src/test/auxiliary/fat_drop.rs
Normal file
23
src/test/auxiliary/fat_drop.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub static mut DROPPED: bool = false;
|
||||
|
||||
pub struct S {
|
||||
_unsized: [u8]
|
||||
}
|
||||
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
DROPPED = true;
|
||||
}
|
||||
}
|
||||
}
|
23
src/test/run-pass/extern_fat_drop.rs
Normal file
23
src/test/run-pass/extern_fat_drop.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:fat_drop.rs
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
extern crate fat_drop;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let s: &mut fat_drop::S = std::mem::uninitialized();
|
||||
std::intrinsics::drop_in_place(s);
|
||||
assert!(fat_drop::DROPPED);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user