提交 e132f767 编写于 作者: A Alex Crichton

rollup merge of #27618: dotdash/drop_fixes

......@@ -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))
}
}
// 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;
}
}
}
// 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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册