|
| 1 | +//! Regression test for https://github.com/rust-lang/rust/issues/39367 |
| 2 | +//! |
| 3 | +//! Tests that lazy static initialization using `Once` and `transmute` |
| 4 | +//! works correctly with a struct that has a default type parameter. |
1 | 5 | //@ run-pass |
2 | 6 |
|
3 | 7 | use std::ops::Deref; |
4 | 8 |
|
5 | | -struct ArenaSet<U: Deref, V=<U as Deref>::Target>(U, &'static V) |
6 | | - where V: 'static + ?Sized; |
| 9 | +struct ArenaSet<U: Deref, V = <U as Deref>::Target>(U, &'static V) |
| 10 | +where |
| 11 | + V: 'static + ?Sized; |
7 | 12 |
|
8 | | -static Z: [u8; 4] = [1,2,3,4]; |
| 13 | +static Z: [u8; 4] = [1, 2, 3, 4]; |
9 | 14 |
|
10 | 15 | fn arena() -> &'static ArenaSet<Vec<u8>> { |
11 | 16 | fn __static_ref_initialize() -> ArenaSet<Vec<u8>> { |
12 | 17 | ArenaSet(vec![], &Z) |
13 | 18 | } |
14 | 19 | unsafe { |
15 | 20 | use std::sync::Once; |
16 | | - fn require_sync<T: Sync>(_: &T) { } |
| 21 | + fn require_sync<T: Sync>(_: &T) {} |
17 | 22 | unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> { |
18 | 23 | use std::mem::transmute; |
19 | 24 | static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut(); |
20 | 25 |
|
21 | 26 | static mut ONCE: Once = Once::new(); |
22 | 27 | ONCE.call_once(|| { |
23 | | - //~^ WARN creating a shared reference to mutable static [static_mut_refs] |
24 | | - DATA = transmute |
25 | | - ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>> |
26 | | - (Box::new(__static_ref_initialize())); |
| 28 | + //~^ WARN creating a shared reference to mutable static [static_mut_refs] |
| 29 | + DATA = transmute::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>(Box::new( |
| 30 | + __static_ref_initialize(), |
| 31 | + )); |
27 | 32 | }); |
28 | 33 |
|
29 | 34 | &*DATA |
|
0 commit comments