2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2023-12-22 12:12:01 +00:00
|
|
|
|
2015-06-28 17:36:46 +00:00
|
|
|
static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
2024-02-17 19:01:56 +00:00
|
|
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
2015-06-28 17:36:46 +00:00
|
|
|
|
2015-06-28 17:38:28 +00:00
|
|
|
struct StaticDoubleLinked {
|
|
|
|
prev: &'static StaticDoubleLinked,
|
|
|
|
next: &'static StaticDoubleLinked,
|
|
|
|
data: i32,
|
2023-12-22 12:12:01 +00:00
|
|
|
head: bool,
|
2015-06-28 17:38:28 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 12:12:01 +00:00
|
|
|
static L1: StaticDoubleLinked = StaticDoubleLinked { prev: &L3, next: &L2, data: 1, head: true };
|
|
|
|
static L2: StaticDoubleLinked = StaticDoubleLinked { prev: &L1, next: &L3, data: 2, head: false };
|
|
|
|
static L3: StaticDoubleLinked = StaticDoubleLinked { prev: &L2, next: &L1, data: 3, head: false };
|
2015-06-28 17:38:28 +00:00
|
|
|
|
2015-06-28 17:36:46 +00:00
|
|
|
pub fn main() {
|
2023-12-22 12:12:01 +00:00
|
|
|
unsafe {
|
|
|
|
assert_eq!(S, *(S as *const *const u8));
|
2024-08-24 03:49:09 +00:00
|
|
|
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 12:12:01 +00:00
|
|
|
}
|
2015-06-28 17:38:28 +00:00
|
|
|
|
|
|
|
let mut test_vec = Vec::new();
|
|
|
|
let mut cur = &L1;
|
|
|
|
loop {
|
|
|
|
test_vec.push(cur.data);
|
|
|
|
cur = cur.next;
|
2023-12-22 12:12:01 +00:00
|
|
|
if cur.head {
|
|
|
|
break;
|
|
|
|
}
|
2015-06-28 17:38:28 +00:00
|
|
|
}
|
2023-12-22 12:12:01 +00:00
|
|
|
assert_eq!(&test_vec, &[1, 2, 3]);
|
2015-06-28 17:38:28 +00:00
|
|
|
|
|
|
|
let mut test_vec = Vec::new();
|
|
|
|
let mut cur = &L1;
|
|
|
|
loop {
|
|
|
|
cur = cur.prev;
|
|
|
|
test_vec.push(cur.data);
|
2023-12-22 12:12:01 +00:00
|
|
|
if cur.head {
|
|
|
|
break;
|
|
|
|
}
|
2015-06-28 17:38:28 +00:00
|
|
|
}
|
2023-12-22 12:12:01 +00:00
|
|
|
assert_eq!(&test_vec, &[3, 2, 1]);
|
2015-06-28 17:36:46 +00:00
|
|
|
}
|