3 // Test that we can handle unsized types with an extern type tail part.
4 // Regression test for issue #91827.
6 #![feature(extern_types)]
14 unsafe impl Sync for Opaque {}
24 pub struct ListImpl<T, const N: usize> {
30 const fn as_slice(&self) -> &[T] {
31 unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) }
35 impl<T, const N: usize> ListImpl<T, N> {
36 const fn as_list(&self) -> &List<T> {
37 unsafe { std::mem::transmute(self) }
41 pub static A: ListImpl<u128, 3> = ListImpl {
45 pub static A_REF: &'static List<u128> = A.as_list();
46 pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list());
48 const fn tail_offset<T>(list: &List<T>) -> isize {
49 unsafe { (addr_of!(list.tail) as *const u8).offset_from(list as *const List<T> as *const u8) }
53 assert_eq!(A_REF.as_slice(), &[5, 6, 7]);
54 // Check that interpreter and code generation agree about the position of the tail field.
55 assert_eq!(A_TAIL_OFFSET, tail_offset(A_REF));