]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issues/issue-39367.rs
Make use of `ptr::null(_mut)` instead of casting zero
[rust.git] / src / test / run-pass / issues / issue-39367.rs
1 // run-pass
2 use std::ops::Deref;
3
4 struct ArenaSet<U: Deref, V=<U as Deref>::Target>(U, &'static V)
5     where V: 'static + ?Sized;
6
7 static Z: [u8; 4] = [1,2,3,4];
8
9 fn arena() -> &'static ArenaSet<Vec<u8>> {
10     fn __static_ref_initialize() -> ArenaSet<Vec<u8>> {
11         ArenaSet(vec![], &Z)
12     }
13     unsafe {
14         use std::sync::Once;
15         fn require_sync<T: Sync>(_: &T) { }
16         unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
17             use std::mem::transmute;
18             static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();
19
20             static mut ONCE: Once = Once::new();
21             ONCE.call_once(|| {
22                 DATA = transmute
23                     ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
24                     (Box::new(__static_ref_initialize()));
25             });
26
27             &*DATA
28         }
29         let static_ref = __stability();
30         require_sync(static_ref);
31         static_ref
32     }
33 }
34
35 fn main() {
36     let &ArenaSet(ref u, v) = arena();
37     assert!(u.is_empty());
38     assert_eq!(v, Z);
39 }