未验证 提交 62c260de 编写于 作者: D Dylan DPC 提交者: GitHub

Rollup merge of #97738 - Kixiron:zst-panic, r=eddyb

Fix ICEs from zsts within unsized types with non-zero offsets

- Fixes #97732
- Fixes ICEs while compiling `alloc` with `-Z randomize-layout`

r? ``@EddyB``
......@@ -216,11 +216,12 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mut result = None;
for i in 0..src_layout.fields.count() {
let src_f = src_layout.field(bx.cx(), i);
assert_eq!(src_layout.fields.offset(i).bytes(), 0);
assert_eq!(dst_layout.fields.offset(i).bytes(), 0);
if src_f.is_zst() {
continue;
}
assert_eq!(src_layout.fields.offset(i).bytes(), 0);
assert_eq!(dst_layout.fields.offset(i).bytes(), 0);
assert_eq!(src_layout.size, src_f.size);
let dst_f = dst_layout.field(bx.cx(), i);
......
// check-pass
#![feature(coerce_unsized)]
// Ensure that unsizing structs that contain ZSTs at non-zero offsets don't ICE
use std::ops::CoerceUnsized;
#[repr(C)]
pub struct BoxWithZstTail<T: ?Sized>(Box<T>, ());
impl<S: ?Sized, T: ?Sized> CoerceUnsized<BoxWithZstTail<T>> for BoxWithZstTail<S> where
Box<S>: CoerceUnsized<Box<T>>
{
}
pub fn noop_dyn_upcast_with_zst_tail(
b: BoxWithZstTail<dyn ToString + Send>,
) -> BoxWithZstTail<dyn ToString> {
b
}
fn main() {
let original = "foo";
let boxed = BoxWithZstTail(Box::new(original) as Box<dyn ToString + Send>, ());
let noop_upcasted = noop_dyn_upcast_with_zst_tail(boxed);
assert_eq!(original, noop_upcasted.0.to_string());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册