Skip to content

Commit a17d8a0

Browse files
authored
Rollup merge of #94728 - compiler-errors:box-allocator-zst-meta, r=michaelwoerister
Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST Basically copy the change in #94043, but for debuginfo. r? `@michaelwoerister` Fixes #94725
2 parents 79f9a0c + 307ee94 commit a17d8a0

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
617617
ty::RawPtr(ty::TypeAndMut { ty: pointee_type, .. }) | ty::Ref(_, pointee_type, _) => {
618618
pointer_or_reference_metadata(cx, t, pointee_type, unique_type_id)
619619
}
620-
ty::Adt(def, _) if def.is_box() => {
620+
// Box<T, A> may have a non-ZST allocator A. In that case, we
621+
// cannot treat Box<T, A> as just an owned alias of `*mut T`.
622+
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
621623
pointer_or_reference_metadata(cx, t, t.boxed_ty(), unique_type_id)
622624
}
623625
ty::FnDef(..) | ty::FnPtr(_) => subroutine_type_metadata(cx, unique_type_id),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// build-pass
2+
// compile-flags: -Cdebuginfo=2
3+
// fixes issue #94725
4+
5+
#![feature(allocator_api)]
6+
7+
use std::alloc::{AllocError, Allocator, Layout};
8+
use std::ptr::NonNull;
9+
10+
struct ZST;
11+
12+
unsafe impl Allocator for &ZST {
13+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
14+
todo!()
15+
}
16+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
17+
todo!()
18+
}
19+
}
20+
21+
fn main() {
22+
let _ = Box::<i32, &ZST>::new_in(43, &ZST);
23+
}

src/test/ui/debuginfo/debuginfo_with_uninhabitable_field_and_unsized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// check-pass
1+
// build-pass
22
// compile-flags: -Cdebuginfo=2
33
// fixes issue #94149
44

0 commit comments

Comments
 (0)