]> git.lizzy.rs Git - rust.git/blob - tests/ui/unsized/issue-97732.rs
Auto merge of #106646 - Amanieu:ilp32-object, r=Mark-Simulacrum
[rust.git] / tests / ui / unsized / issue-97732.rs
1 // check-pass
2
3 #![feature(coerce_unsized)]
4
5 // Ensure that unsizing structs that contain ZSTs at non-zero offsets don't ICE
6
7 use std::ops::CoerceUnsized;
8
9 #[repr(C)]
10 pub struct BoxWithZstTail<T: ?Sized>(Box<T>, ());
11
12 impl<S: ?Sized, T: ?Sized> CoerceUnsized<BoxWithZstTail<T>> for BoxWithZstTail<S> where
13     Box<S>: CoerceUnsized<Box<T>>
14 {
15 }
16
17 pub fn noop_dyn_upcast_with_zst_tail(
18     b: BoxWithZstTail<dyn ToString + Send>,
19 ) -> BoxWithZstTail<dyn ToString> {
20     b
21 }
22
23 fn main() {
24     let original = "foo";
25     let boxed = BoxWithZstTail(Box::new(original) as Box<dyn ToString + Send>, ());
26     let noop_upcasted = noop_dyn_upcast_with_zst_tail(boxed);
27     assert_eq!(original, noop_upcasted.0.to_string());
28 }