Merge pull request #137 from rust-lang/fix/box-alloc-ice
Fix ice in box alloc
This commit is contained in:
commit
d63ea3e037
@ -443,12 +443,22 @@ pub trait Deref {
|
||||
fn deref(&self) -> &Self::Target;
|
||||
}
|
||||
|
||||
pub trait Allocator {
|
||||
}
|
||||
|
||||
pub struct Global;
|
||||
|
||||
impl Allocator for Global {}
|
||||
|
||||
#[lang = "owned_box"]
|
||||
pub struct Box<T: ?Sized>(*mut T);
|
||||
pub struct Box<
|
||||
T: ?Sized,
|
||||
A: Allocator = Global,
|
||||
>(*mut T, A);
|
||||
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
||||
|
||||
impl<T: ?Sized> Drop for Box<T> {
|
||||
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
|
||||
fn drop(&mut self) {
|
||||
// drop is currently performed by compiler.
|
||||
}
|
||||
@ -468,7 +478,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
||||
}
|
||||
|
||||
#[lang = "box_free"]
|
||||
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
|
||||
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
|
||||
libc::free(ptr as *mut u8);
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
|
||||
ty::Ref(..) | ty::RawPtr(_) => {
|
||||
return self.field(cx, index).gcc_type(cx, true);
|
||||
}
|
||||
ty::Adt(def, _) if def.is_box() => {
|
||||
// only wide pointer boxes are handled as pointers
|
||||
// thin pointer boxes with scalar allocators are handled by the general logic below
|
||||
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
|
||||
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty());
|
||||
return cx.layout_of(ptr_ty).scalar_pair_element_gcc_type(cx, index, immediate);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user