@@ -37,14 +37,12 @@ impl Destructible for S {
3737 last_1. with ( |rc| * rc. borrow_mut ( ) = ( * this) . with ( |__s| __s. v ) ) ;
3838 }
3939}
40- pub fn by_value_2 ( s : S ) -> i32 {
41- let s: Value < S > = Rc :: new ( RefCell :: new ( s) ) ;
40+ pub fn by_value_2 ( s : Ptr < S > ) -> i32 {
4241 assert ! ( ( destroyed_0. with( |rc| * rc. borrow( ) ) == 0 ) ) ;
43- return { ( * s . borrow ( ) ) . v } ;
42+ return s . with ( |__s| __s . v ) ;
4443}
45- pub fn with_default_3 ( s : S ) -> i32 {
46- let s: Value < S > = Rc :: new ( RefCell :: new ( s) ) ;
47- return { ( * s. borrow ( ) ) . v } ;
44+ pub fn with_default_3 ( s : Ptr < S > ) -> i32 {
45+ return s. with ( |__s| __s. v ) ;
4846}
4947#[ derive(
5048 Copy ,
@@ -72,26 +70,51 @@ fn main_0() -> i32 {
7270 let s: Value < S > = Rc :: new ( RefCell :: new ( S { v : 1 } ) ) ;
7371 let _dtor_s =
7472 std:: mem:: DropGuard :: new ( s. clone ( ) , |__p| Destructible :: destroy ( & __p. as_pointer ( ) ) ) ;
75- assert ! ( ( ( { by_value_2( { ( * s. borrow( ) ) . clone( ) } , ) } ) == 1 ) ) ;
73+ assert ! (
74+ ( {
75+ ( ( {
76+ let _s: Value <S > = Rc :: new( RefCell :: new( ( * s. borrow( ) ) . clone( ) ) ) ;
77+ by_value_2( _s. as_pointer( ) )
78+ } ) == 1 )
79+ } )
80+ ) ;
7681 assert ! (
7782 ( destroyed_0. with( |rc| * rc. borrow( ) ) == 1 ) && ( last_1. with( |rc| * rc. borrow( ) ) == 1 )
7883 ) ;
7984 }
8085 assert ! ( ( destroyed_0. with( |rc| * rc. borrow( ) ) == 2 ) ) ;
8186 destroyed_0. with ( |rc| * rc. borrow_mut ( ) = 0 ) ;
82- assert ! ( ( ( { by_value_2( S { v: 2 } , ) } ) == 2 ) ) ;
87+ assert ! (
88+ ( ( {
89+ let _s: Value <S > = Rc :: new( RefCell :: new( S { v: 2 } ) ) ;
90+ by_value_2( _s. as_pointer( ) )
91+ } ) == 2 )
92+ ) ;
8393 assert ! ( ( destroyed_0. with( |rc| * rc. borrow( ) ) == 1 ) && ( last_1. with( |rc| * rc. borrow( ) ) == 2 ) ) ;
8494 destroyed_0. with ( |rc| * rc. borrow_mut ( ) = 0 ) ;
85- assert ! ( ( ( { with_default_3( S { v: 5 } , ) } ) == 5 ) ) ;
95+ assert ! (
96+ ( ( {
97+ let _s: Value <S > = Rc :: new( RefCell :: new( S { v: 5 } ) ) ;
98+ with_default_3( _s. as_pointer( ) )
99+ } ) == 5 )
100+ ) ;
86101 assert ! ( ( destroyed_0. with( |rc| * rc. borrow( ) ) == 1 ) && ( last_1. with( |rc| * rc. borrow( ) ) == 5 ) ) ;
87102 destroyed_0. with ( |rc| * rc. borrow_mut ( ) = 0 ) ;
88103 {
89104 let h: Value < Holder > = Rc :: new ( RefCell :: new ( <Holder >:: zero_init ( ) ) ) ;
90- HolderImpl :: construct ( & h. as_pointer ( ) , { S { v : 3 } } ) ;
105+ {
106+ let __tmp_0: Value < S > = Rc :: new ( RefCell :: new ( S { v : 3 } ) ) ;
107+ HolderImpl :: construct ( & h. as_pointer ( ) , { __tmp_0. as_pointer ( ) } )
108+ } ;
91109 assert ! (
92110 ( destroyed_0. with( |rc| * rc. borrow( ) ) == 1 ) && ( last_1. with( |rc| * rc. borrow( ) ) == 3 )
93111 ) ;
94- assert ! ( ( ( { HolderImpl :: add( & h. as_pointer( ) , S { v: 4 } , ) } ) == 7 ) ) ;
112+ assert ! (
113+ ( ( {
114+ let _s: Value <S > = Rc :: new( RefCell :: new( S { v: 4 } ) ) ;
115+ HolderImpl :: add( & h. as_pointer( ) , _s. as_pointer( ) )
116+ } ) == 7 )
117+ ) ;
95118 assert ! (
96119 ( destroyed_0. with( |rc| * rc. borrow( ) ) == 2 ) && ( last_1. with( |rc| * rc. borrow( ) ) == 4 )
97120 ) ;
@@ -100,17 +123,15 @@ fn main_0() -> i32 {
100123 return 0 ;
101124}
102125pub trait HolderImpl {
103- fn construct ( & self , s : S ) ;
104- fn add ( & self , s : S ) -> i32 ;
126+ fn construct ( & self , s : Ptr < S > ) ;
127+ fn add ( & self , s : Ptr < S > ) -> i32 ;
105128}
106129impl HolderImpl for Ptr < Holder > {
107- fn construct ( & self , s : S ) {
108- let s: Value < S > = Rc :: new ( RefCell :: new ( s) ) ;
109- field ! ( ( * self ) , v) . write ( { ( * s. borrow ( ) ) . v } ) ;
130+ fn construct ( & self , s : Ptr < S > ) {
131+ field ! ( ( * self ) , v) . write ( s. with ( |__s| __s. v ) ) ;
110132 }
111- fn add ( & self , s : S ) -> i32 {
112- let s: Value < S > = Rc :: new ( RefCell :: new ( s) ) ;
113- return ( ( * self ) . with ( |__s| __s. v ) + { ( * s. borrow ( ) ) . v } ) ;
133+ fn add ( & self , s : Ptr < S > ) -> i32 {
134+ return ( ( * self ) . with ( |__s| __s. v ) + s. with ( |__s| __s. v ) ) ;
114135 }
115136}
116137pub fn __cpp2rust_init_globals ( ) {
0 commit comments