| 1 | mod first { |
| 2 | use ghost::phantom; |
| 3 | |
| 4 | #[phantom] |
| 5 | struct MyPhantom<T: ?Sized>; |
| 6 | |
| 7 | #[test] |
| 8 | fn test() { |
| 9 | // Proof that MyPhantom behaves like PhantomData. |
| 10 | let _: MyPhantom<u8> = MyPhantom::<u8>; |
| 11 | assert_eq!(0, std::mem::size_of::<MyPhantom<u8>>()); |
| 12 | } |
| 13 | |
| 14 | // Proof that MyPhantom is not just a re-export of PhantomData. |
| 15 | // If it were a re-export, these would be conflicting impls. |
| 16 | trait Trait {} |
| 17 | impl<T> Trait for std::marker::PhantomData<T> {} |
| 18 | impl<T> Trait for MyPhantom<T> {} |
| 19 | |
| 20 | // Proof that MyPhantom is local to the current crate. |
| 21 | impl<T> MyPhantom<T> {} |
| 22 | } |
| 23 | |
| 24 | mod second { |
| 25 | use ghost::phantom; |
| 26 | |
| 27 | #[phantom] |
| 28 | #[derive(Copy, Clone, Default, Hash, PartialOrd, Ord, PartialEq, Eq, Debug)] |
| 29 | struct Crazy<'a, V: 'a, T> |
| 30 | where |
| 31 | &'a V: IntoIterator<Item = T>; |
| 32 | |
| 33 | #[test] |
| 34 | fn test() { |
| 35 | let _ = Crazy::<'static, Vec<String>, &'static String>; |
| 36 | |
| 37 | // Lifetime elision. |
| 38 | let crazy = Crazy::<Vec<String>, &String>; |
| 39 | println!("{:?}", crazy); |
| 40 | } |
| 41 | } |