1 #![feature(unsize, coerce_unsized)]
3 use std::collections::hash_map::DefaultHasher;
28 let x = *t.other.other;
40 // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
41 assert_eq!({x.a}, 42);
42 assert_eq!({x.b}, 99);
45 assert_eq!({x.b}, 77);
47 test(Test2 { x: 0, other: &Test1 { x: 0, other: &42 }});
53 struct UnalignedPtr<'a, T: ?Sized>
59 impl<'a, T, U> std::ops::CoerceUnsized<UnalignedPtr<'a, U>> for UnalignedPtr<'a, T>
61 T: std::marker::Unsize<U> + ?Sized,
66 let arr_unaligned: UnalignedPtr<[i32; 3]> = UnalignedPtr { data: &arr };
67 let arr_unaligned: UnalignedPtr<[i32]> = arr_unaligned;
68 let _unused = &arr_unaligned; // forcing an allocation, which could also yield "unaligned write"-errors
75 // Do an (aligned) load
77 // For the fun of it, test alignment
78 assert_eq!(&self.0 as *const _ as usize % std::mem::align_of::<u32>(), 0);
84 f1: u8, // this should move the second field to something not very aligned
88 let p = Packed { f1: 42, f2: Wrap(23) };
92 fn test_inner_packed() {
93 // Even if just the inner struct is packed, accesses to the outer field can get unaligned.
94 // Make sure that works.
100 struct Outer(u8, Inner);
102 let o = Outer(0, Inner(42));
114 static FOO: Foo = Foo { i: 42 };
116 assert_eq!({FOO.i}, 42);
121 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
128 let x = P {a: 1usize, b: 2u8, c: 3usize};
129 let y = P {a: 1usize, b: 2u8, c: 4usize};
131 let _clone = x.clone();
133 assert_eq!(x.partial_cmp(&y).unwrap(), x.cmp(&y));
134 x.hash(&mut DefaultHasher::new());