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``
This commit is contained in:
commit
62c260de8c
2 changed files with 31 additions and 2 deletions
|
@ -216,11 +216,12 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
for i in 0..src_layout.fields.count() {
|
for i in 0..src_layout.fields.count() {
|
||||||
let src_f = src_layout.field(bx.cx(), i);
|
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() {
|
if src_f.is_zst() {
|
||||||
continue;
|
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);
|
assert_eq!(src_layout.size, src_f.size);
|
||||||
|
|
||||||
let dst_f = dst_layout.field(bx.cx(), i);
|
let dst_f = dst_layout.field(bx.cx(), i);
|
||||||
|
|
28
src/test/ui/unsized/issue-97732.rs
Normal file
28
src/test/ui/unsized/issue-97732.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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());
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue