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