@@ -7,11 +7,11 @@ use std::io::{Read, Seek, Write};
77use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
88use std:: rc:: Rc ;
99pub unsafe fn foo_0 ( mut a : i32 , mut b : Option < i32 > ) -> i32 {
10- let mut b: i32 = b. unwrap_or ( 10 ) ;
10+ let mut b: i32 = b. unwrap_or_else ( || unsafe { 10 } ) ;
1111 return ( ( a) + ( b) ) ;
1212}
1313pub unsafe fn baz_1 ( mut a : * mut i32 , mut b : Option < * mut i32 > ) -> bool {
14- let mut b: * mut i32 = b. unwrap_or ( std:: ptr:: null_mut ( ) ) ;
14+ let mut b: * mut i32 = b. unwrap_or_else ( || unsafe { std:: ptr:: null_mut ( ) } ) ;
1515 return ( ( a) == ( b) ) ;
1616}
1717#[ repr( C ) ]
@@ -21,7 +21,7 @@ pub struct Bar {
2121}
2222impl Bar {
2323 pub unsafe fn new ( mut v : Option < i32 > ) -> Self {
24- let mut v: i32 = v. unwrap_or ( 1 ) ;
24+ let mut v: i32 = v. unwrap_or_else ( || unsafe { 1 } ) ;
2525 let mut this = Self { v : v } ;
2626 this
2727 }
@@ -31,6 +31,39 @@ impl Default for Bar {
3131 unsafe { Bar :: new ( None ) }
3232 }
3333}
34+ pub static mut counter_2: std:: cell:: LazyCell < i32 > = std:: cell:: LazyCell :: new ( || unsafe { 0 } ) ;
35+ pub unsafe fn next_3 ( ) -> i32 {
36+ return ( * std:: cell:: LazyCell :: force_mut ( & mut * & raw mut counter_2) ) . prefix_inc ( ) ;
37+ }
38+ pub unsafe fn lazy_4 ( mut x : Option < i32 > ) -> i32 {
39+ let mut x: i32 = x. unwrap_or_else ( || unsafe { ( unsafe { next_3 ( ) } ) } ) ;
40+ return x;
41+ }
42+ pub unsafe fn by_ref_5 ( b : Option < * const Bar > ) -> i32 {
43+ let mut __b_default: Option < Bar > = None ;
44+ let mut b: * const Bar =
45+ b. unwrap_or_else ( || unsafe { __b_default. insert ( Bar :: new ( { Some ( 7 ) } ) ) as * const Bar } ) ;
46+ return ( * b) . v ;
47+ }
48+ pub static mut global_bar_6: std:: cell:: LazyCell < Bar > =
49+ std:: cell:: LazyCell :: new ( || unsafe { Bar :: new ( { Some ( 9 ) } ) } ) ;
50+ pub unsafe fn by_global_ref_7 ( b : Option < * const Bar > ) -> i32 {
51+ let mut b: * const Bar = b. unwrap_or_else ( || unsafe {
52+ & ( * std:: cell:: LazyCell :: force_mut ( & mut * & raw mut global_bar_6) )
53+ } ) ;
54+ return ( * b) . v ;
55+ }
56+ #[ repr( C ) ]
57+ #[ derive( Copy , Clone , VaArg , FnPtrArg , Default ) ]
58+ pub struct Holder_int_ {
59+ pub v : i32 ,
60+ }
61+ impl Holder_int_ {
62+ pub unsafe fn new ( mut v : i32 ) -> Self {
63+ let mut this = Self { v : v } ;
64+ this
65+ }
66+ }
3467pub fn main ( ) {
3568 unsafe {
3669 __cpp2rust_init_globals ( ) ;
@@ -56,6 +89,29 @@ unsafe fn main_0() -> i32 {
5689 let mut arr: [ Bar ; 3 ] = [ Bar :: new ( None ) , Bar :: new ( None ) , Bar :: new ( None ) ] ;
5790 assert ! ( ( ( arr[ ( 0 ) as usize ] . v) == ( 1 ) ) ) ;
5891 assert ! ( ( ( arr[ ( 2 ) as usize ] . v) == ( 1 ) ) ) ;
92+ assert ! ( ( ( unsafe { lazy_4( Some ( 5 ) , ) } ) == ( 5 ) ) ) ;
93+ assert ! ( ( ( * std:: cell:: LazyCell :: force_mut( & mut * & raw mut counter_2) ) == ( 0 ) ) ) ;
94+ assert ! ( ( ( unsafe { lazy_4( None , ) } ) == ( 1 ) ) ) ;
95+ assert ! ( ( ( * std:: cell:: LazyCell :: force_mut( & mut * & raw mut counter_2) ) == ( 1 ) ) ) ;
96+ assert ! ( ( ( unsafe { by_ref_5( None , ) } ) == ( 7 ) ) ) ;
97+ assert ! (
98+ ( ( unsafe {
99+ let mut _b: Bar = Bar :: new( { Some ( 3 ) } ) ;
100+ by_ref_5( Some ( & mut _b) )
101+ } ) == ( 3 ) )
102+ ) ;
103+ assert ! ( ( ( unsafe { by_global_ref_7( None , ) } ) == ( 9 ) ) ) ;
104+ assert ! (
105+ ( ( unsafe {
106+ let mut _b: Bar = Bar :: new( { Some ( 4 ) } ) ;
107+ by_global_ref_7( Some ( & mut _b) )
108+ } ) == ( 4 ) )
109+ ) ;
110+ let mut h: Holder_int_ = Holder_int_ :: new ( { 4 } ) ;
111+ assert ! ( ( ( h. v) == ( 4 ) ) ) ;
59112 return 0 ;
60113}
61- pub unsafe fn __cpp2rust_init_globals ( ) { }
114+ pub unsafe fn __cpp2rust_init_globals ( ) {
115+ std:: cell:: LazyCell :: force ( & * & raw const counter_2) ;
116+ std:: cell:: LazyCell :: force ( & * & raw const global_bar_6) ;
117+ }
0 commit comments