]> git.lizzy.rs Git - rust.git/commitdiff
fix another assumption about box
authorDrMeepster <19316085+DrMeepster@users.noreply.github.com>
Sat, 12 Mar 2022 01:00:56 +0000 (17:00 -0800)
committerDrMeepster <19316085+DrMeepster@users.noreply.github.com>
Sat, 12 Mar 2022 01:00:56 +0000 (17:00 -0800)
compiler/rustc_codegen_ssa/src/mir/operand.rs
src/test/ui/box/large-allocator-ice.rs

index 66be58cf62ca03ac6abbb5778a6225e39909543f..858f71ebc3933b9a70befcbe4e6ad65294fa574a 100644 (file)
@@ -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);
index 3ef1171ff50d9c8328d596031a684b0fdb9a82cd..b3a882ff089b00764ec7a451b7d102436435dedd 100644 (file)
@@ -1,5 +1,6 @@
 // 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);
 }