提交 ed2a69c4 编写于 作者: B bors

Auto merge of #94873 - DrMeepster:box_alloc_ice3, r=oli-obk

Fix ICE when using Box<T, A>, again

Sequel to #94043, fixes #94835.
......@@ -126,7 +126,14 @@ pub fn deref<Cx: LayoutTypeMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> {
.ty;
let (llptr, llextra) = match self.val {
OperandValue::Immediate(llptr) => (llptr, None),
OperandValue::Pair(llptr, llextra) => (llptr, Some(llextra)),
OperandValue::Pair(llptr, llextra) => {
// if the box's allocator isn't a ZST, then "llextra" is actually the allocator
if self.layout.ty.is_box() && !self.layout.field(cx, 1).is_zst() {
(llptr, None)
} else {
(llptr, Some(llextra))
}
}
OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self),
};
let layout = cx.layout_of(projected_ty);
......
// build-pass
#![feature(allocator_api)]
#![allow(unused_must_use)]
use std::alloc::Allocator;
......@@ -20,4 +21,9 @@ unsafe fn deallocate(&self, _: std::ptr::NonNull<u8>, _: std::alloc::Layout) {
fn main() {
Box::new_in((), &std::alloc::Global);
Box::new_in((), BigAllocator([0; 2]));
generic_function(0);
}
fn generic_function<T>(val: T) {
*Box::new_in(val, &std::alloc::Global);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册