@@ -7,11 +7,11 @@ use std::io::{Read, Seek, Write};
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
99pub fn foo_0 ( mut a : i32 , b : Option < i32 > ) -> i32 {
10- let mut b: i32 = b. unwrap_or ( 10 ) ;
10+ let mut b: i32 = b. unwrap_or_else ( || 10 ) ;
1111 return ( a + b) ;
1212}
1313pub fn baz_1 ( mut a : Ptr < i32 > , b : Option < Ptr < i32 > > ) -> bool {
14- let mut b: Ptr < i32 > = b. unwrap_or ( Ptr :: < i32 > :: null ( ) ) ;
14+ let mut b: Ptr < i32 > = b. unwrap_or_else ( || Ptr :: < i32 > :: null ( ) ) ;
1515 return ( { a } == { b } ) ;
1616}
1717#[ derive( Clone , Record , ByteRepr , VaArg , FnPtrArg ) ]
@@ -22,7 +22,7 @@ pub struct Bar {
2222}
2323impl Bar {
2424 pub fn new ( v : Option < i32 > ) -> Self {
25- let mut v: i32 = v. unwrap_or ( 1 ) ;
25+ let mut v: i32 = v. unwrap_or_else ( || 1 ) ;
2626 Self { v : v }
2727 }
2828}
@@ -31,6 +31,43 @@ impl Default for Bar {
3131 { Bar :: new ( None ) }
3232 }
3333}
34+ thread_local ! (
35+ pub static counter_2: Value <i32 > = Rc :: new( RefCell :: new( 0 ) ) ;
36+ ) ;
37+ pub fn next_3 ( ) -> i32 {
38+ return ( * counter_2. with ( Value :: clone) . borrow_mut ( ) ) . prefix_inc ( ) ;
39+ }
40+ pub fn lazy_4 ( x : Option < i32 > ) -> i32 {
41+ let mut x: i32 = x. unwrap_or_else ( || ( { next_3 ( ) } ) ) ;
42+ return x;
43+ }
44+ pub fn by_ref_5 ( b : Option < Ptr < Bar > > ) -> i32 {
45+ let mut __b_default: Option < Value < Bar > > = None ;
46+ let b: Ptr < Bar > = b. unwrap_or_else ( || {
47+ __b_default
48+ . insert ( Rc :: new ( RefCell :: new ( Bar :: new ( { Some ( 7 ) } ) ) ) )
49+ . as_pointer ( )
50+ } ) ;
51+ return b. with ( |__s| __s. v ) ;
52+ }
53+ thread_local ! (
54+ pub static global_bar_6: Value <Bar > = Rc :: new( RefCell :: new( Bar :: new( { Some ( 9 ) } ) ) ) ;
55+ ) ;
56+ pub fn by_global_ref_7 ( b : Option < Ptr < Bar > > ) -> i32 {
57+ let b: Ptr < Bar > = b. unwrap_or_else ( || global_bar_6. with ( |v| v. as_pointer ( ) ) ) ;
58+ return b. with ( |__s| __s. v ) ;
59+ }
60+ #[ derive( Clone , Record , ByteRepr , VaArg , FnPtrArg , Default ) ]
61+ #[ byte_size( 4 ) ]
62+ pub struct Holder_int_ {
63+ #[ offset( 0 ) ]
64+ pub v : i32 ,
65+ }
66+ impl Holder_int_ {
67+ pub fn new ( mut v : i32 ) -> Self {
68+ Self { v : v }
69+ }
70+ }
3471pub fn main ( ) {
3572 __cpp2rust_init_globals ( ) ;
3673 std:: process:: exit ( main_0 ( ) ) ;
@@ -54,6 +91,29 @@ fn main_0() -> i32 {
5491 let mut arr: [ Bar ; 3 ] = [ Bar :: new ( None ) , Bar :: new ( None ) , Bar :: new ( None ) ] ;
5592 assert ! ( ( { arr[ ( 0 ) as usize ] . v } == 1 ) ) ;
5693 assert ! ( ( { arr[ ( 2 ) as usize ] . v } == 1 ) ) ;
94+ assert ! ( ( ( { lazy_4( Some ( 5 ) , ) } ) == 5 ) ) ;
95+ assert ! ( ( counter_2. with( |rc| * rc. borrow( ) ) == 0 ) ) ;
96+ assert ! ( ( ( { lazy_4( None , ) } ) == 1 ) ) ;
97+ assert ! ( ( counter_2. with( |rc| * rc. borrow( ) ) == 1 ) ) ;
98+ assert ! ( ( ( { by_ref_5( None , ) } ) == 7 ) ) ;
99+ assert ! (
100+ ( ( {
101+ let _b: Value <Bar > = Rc :: new( RefCell :: new( Bar :: new( { Some ( 3 ) } ) ) ) ;
102+ by_ref_5( Some ( _b. as_pointer( ) ) )
103+ } ) == 3 )
104+ ) ;
105+ assert ! ( ( ( { by_global_ref_7( None , ) } ) == 9 ) ) ;
106+ assert ! (
107+ ( ( {
108+ let _b: Value <Bar > = Rc :: new( RefCell :: new( Bar :: new( { Some ( 4 ) } ) ) ) ;
109+ by_global_ref_7( Some ( _b. as_pointer( ) ) )
110+ } ) == 4 )
111+ ) ;
112+ let mut h: Holder_int_ = Holder_int_ :: new ( { 4 } ) ;
113+ assert ! ( ( h. v == 4 ) ) ;
57114 return 0 ;
58115}
59- pub fn __cpp2rust_init_globals ( ) { }
116+ pub fn __cpp2rust_init_globals ( ) {
117+ let _ = counter_2. with ( |_| ( ) ) ;
118+ let _ = global_bar_6. with ( |_| ( ) ) ;
119+ }
0 commit comments