3 // Test that we can handle unsized types with an extern type tail part.
4 // Regression test for issue #91827.
6 #![feature(const_ptr_offset_from)]
7 #![feature(const_slice_from_raw_parts)]
8 #![feature(extern_types)]
10 use std::ptr::addr_of;
16 unsafe impl Sync for Opaque {}
26 pub struct ListImpl<T, const N: usize> {
32 const fn as_slice(&self) -> &[T] {
33 unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) }
37 impl<T, const N: usize> ListImpl<T, N> {
38 const fn as_list(&self) -> &List<T> {
39 unsafe { std::mem::transmute(self) }
43 pub static A: ListImpl<u128, 3> = ListImpl {
47 pub static A_REF: &'static List<u128> = A.as_list();
48 pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list());
50 const fn tail_offset<T>(list: &List<T>) -> isize {
51 unsafe { (addr_of!(list.tail) as *const u8).offset_from(list as *const List<T> as *const u8) }
55 assert_eq!(A_REF.as_slice(), &[5, 6, 7]);
56 // Check that interpreter and code generation agree about the position of the tail field.
57 assert_eq!(A_TAIL_OFFSET, tail_offset(A_REF));