]> git.lizzy.rs Git - rust.git/blob - src/test/ui/statics/static-recursive.rs
Auto merge of #95454 - randomicon00:fix95444, r=wesleywiser
[rust.git] / src / test / ui / statics / static-recursive.rs
1 // run-pass
2 static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
3
4 struct StaticDoubleLinked {
5     prev: &'static StaticDoubleLinked,
6     next: &'static StaticDoubleLinked,
7     data: i32,
8     head: bool
9 }
10
11 static L1: StaticDoubleLinked = StaticDoubleLinked{prev: &L3, next: &L2, data: 1, head: true};
12 static L2: StaticDoubleLinked = StaticDoubleLinked{prev: &L1, next: &L3, data: 2, head: false};
13 static L3: StaticDoubleLinked = StaticDoubleLinked{prev: &L2, next: &L1, data: 3, head: false};
14
15
16 pub fn main() {
17     unsafe { assert_eq!(S, *(S as *const *const u8)); }
18
19     let mut test_vec = Vec::new();
20     let mut cur = &L1;
21     loop {
22         test_vec.push(cur.data);
23         cur = cur.next;
24         if cur.head { break }
25     }
26     assert_eq!(&test_vec, &[1,2,3]);
27
28     let mut test_vec = Vec::new();
29     let mut cur = &L1;
30     loop {
31         cur = cur.prev;
32         test_vec.push(cur.data);
33         if cur.head { break }
34     }
35     assert_eq!(&test_vec, &[3,2,1]);
36 }