@@ -4,14 +4,8 @@ mod common;
44use common:: * ;
55
66test_verify_one_file_with_options ! {
7- #[ test] test_basic [ "new-mut-ref" , "--no-lifetime" ] => verus_code! {
8- broadcast axiom fn resolved_defn<T >( a: & mut T )
9- ensures
10- #[ trigger] has_resolved( a) ==> mut_ref_current( a) == mut_ref_future( a) ;
11-
7+ #[ test] test_basic [ "new-mut-ref" ] => verus_code! {
128 fn test_no_update( ) {
13- broadcast use resolved_defn;
14-
159 let mut u: u64 = 20 ;
1610 let u_ref: & mut u64 = & mut u;
1711
@@ -21,8 +15,6 @@ test_verify_one_file_with_options! {
2115 }
2216
2317 fn test_basic_update( ) {
24- broadcast use resolved_defn;
25-
2618 let mut u: u64 = 20 ;
2719 let u_ref: & mut u64 = & mut u;
2820
@@ -36,8 +28,6 @@ test_verify_one_file_with_options! {
3628 struct Pair <A , B >( A , B ) ;
3729
3830 fn test_field_update( ) {
39- broadcast use resolved_defn;
40-
4131 let mut u: Pair <u64 , u64 > = Pair ( 20 , 20 ) ;
4232 let u_ref: & mut Pair <u64 , u64 > = & mut u;
4333
@@ -50,8 +40,6 @@ test_verify_one_file_with_options! {
5040 }
5141
5242 fn test_field_update2( ) {
53- broadcast use resolved_defn;
54-
5543 let mut u: Pair <u64 , u64 > = Pair ( 20 , 20 ) ;
5644 let u_ref: & mut u64 = & mut u. 0 ;
5745
@@ -64,21 +52,21 @@ test_verify_one_file_with_options! {
6452 }
6553
6654 fn test_mut_ref_in_pair( ) {
67- broadcast use resolved_defn;
68-
6955 let mut u: u64 = 20 ;
7056 let u_ref: Pair <& mut u64 , u64 > = Pair ( & mut u, 70 ) ;
7157
7258 * u_ref. 0 = 30 ;
7359
74- proof { resolve( u_ref. 0 ) }
60+ proof {
61+ resolve( u_ref) ;
62+ assert( has_resolved( u_ref) ) ;
63+ assert( has_resolved( u_ref. 0 ) ) ;
64+ }
7565
7666 assert( u == 30 ) ;
7767 }
7868
7969 fn test_reborrow( ) {
80- broadcast use resolved_defn;
81-
8270 let mut u: u64 = 20 ;
8371 let u_ref: & mut u64 = & mut u;
8472
@@ -105,7 +93,7 @@ test_verify_one_file_with_options! {
10593}
10694
10795test_verify_one_file_with_options ! {
108- #[ test] test_spec_functions_ok [ "new-mut-ref" , "--no-lifetime" ] => verus_code! {
96+ #[ test] test_spec_functions_ok [ "new-mut-ref" ] => verus_code! {
10997 spec fn test<T >( x: & mut T ) -> T {
11098 mut_ref_current( x)
11199 }
@@ -123,17 +111,132 @@ test_verify_one_file_with_options! {
123111}
124112
125113test_verify_one_file_with_options ! {
126- #[ test] test_mut_ref_future_proph [ "new-mut-ref" , "--no-lifetime" ] => verus_code! {
114+ #[ test] test_mut_ref_future_proph [ "new-mut-ref" ] => verus_code! {
127115 spec fn test<T >( x: & mut T ) -> T {
128116 mut_ref_future( x)
129117 }
130118 } => Err ( err) => assert_vir_error_msg( err, "cannot use prophecy-dependent function `mut_ref_future` in prophecy-independent context" )
131119}
132120
133121test_verify_one_file_with_options ! {
134- #[ test] test_resolved_proph [ "new-mut-ref" , "--no-lifetime" ] => verus_code! {
122+ #[ test] test_resolved_proph [ "new-mut-ref" ] => verus_code! {
135123 spec fn test<T >( x: & mut T ) -> bool {
136124 has_resolved( x)
137125 }
138126 } => Err ( err) => assert_vir_error_msg( err, "cannot use prophecy-dependent predicate `has_resolved` in prophecy-independent context" )
139127}
128+
129+ test_verify_one_file_with_options ! {
130+ #[ test] test_resolved_axioms [ "new-mut-ref" ] => verus_code! {
131+ use vstd:: prelude:: * ;
132+
133+ proof fn test_pair<A , B >( pair: ( A , B ) ) {
134+ assert( has_resolved( pair) ==> has_resolved( pair. 0 ) ) ;
135+ assert( has_resolved( pair) ==> has_resolved( pair. 1 ) ) ;
136+ }
137+
138+ proof fn test_option<A >( opt: Option <A >) {
139+ match opt {
140+ Some ( o) => {
141+ assert( has_resolved( opt) ==> has_resolved( o) ) ;
142+ }
143+ None => { }
144+ }
145+ }
146+
147+ struct Pair <A , B > {
148+ x: A ,
149+ y: B ,
150+ }
151+
152+ proof fn test_pair_struct<A , B >( pair: Pair <A , B >) {
153+ assert( has_resolved( pair) ==> has_resolved( pair. x) ) ;
154+ assert( has_resolved( pair) ==> has_resolved( pair. y) ) ;
155+ }
156+
157+ proof fn test_box<A >( b: Box <A >) {
158+ assert( has_resolved( b) ==> has_resolved( * b) ) ;
159+ }
160+
161+ proof fn test_tracked<A >( t: Tracked <A >) {
162+ assert( has_resolved( t) ==> has_resolved( t@) ) ;
163+ }
164+
165+ proof fn test_ghost_fail<A >( t: Ghost <A >) {
166+ assert( has_resolved( t) ==> has_resolved( t@) ) ; // FAILS
167+ }
168+
169+ proof fn test_ref_fail<A >( t: & A ) {
170+ assert( has_resolved( t) ==> has_resolved( * t) ) ; // FAILS
171+ }
172+
173+ proof fn test_rc_fail<A >( t: std:: rc:: Rc <A >) {
174+ assert( has_resolved( t) ==> has_resolved( * t) ) ; // FAILS
175+ }
176+
177+ proof fn test_arc_fail<A >( t: std:: sync:: Arc <A >) {
178+ assert( has_resolved( t) ==> has_resolved( * t) ) ; // FAILS
179+ }
180+
181+ proof fn test_mut_ref<A >( t: & mut A ) {
182+ assert( has_resolved( t) ==> mut_ref_current( t) == mut_ref_future( t) ) ;
183+ }
184+
185+ proof fn test_mut_ref_fail<A >( t: & mut A ) {
186+ assert( has_resolved( t) ==> has_resolved( mut_ref_current( t) ) ) ; // FAILS
187+ }
188+
189+ proof fn test_mut_ref_fail2<A >( t: & mut A ) {
190+ assert( has_resolved( t) ==> has_resolved( mut_ref_future( t) ) ) ; // FAILS
191+ }
192+ } => Err ( err) => assert_fails( err, 6 )
193+ }
194+
195+ test_verify_one_file_with_options ! {
196+ #[ test] test_resolve_axioms_in_context [ "new-mut-ref" ] => verus_code! {
197+ use vstd:: prelude:: * ;
198+
199+ fn box_with_mut_ref( ) {
200+ let mut x: u64 = 0 ;
201+
202+ let x_ref = & mut x;
203+ let x_ref_box = Box :: new( x_ref) ;
204+
205+ * * x_ref_box = 13 ;
206+
207+ proof { resolve( x_ref_box) ; }
208+
209+ assert( x == 13 ) ;
210+ }
211+
212+ fn shr_ref_with_mut_ref( ) {
213+ let mut x: u64 = 0 ;
214+
215+ let x_ref = & mut x;
216+ let x_ref_ref = & x_ref;
217+
218+ proof { resolve( x_ref_ref) ; }
219+
220+ assert( has_resolved( x_ref) ) ; // FAILS
221+
222+ * x_ref = 20 ;
223+ proof { resolve( x_ref) ; }
224+ }
225+
226+ fn mut_ref_with_mut_ref( ) {
227+ let mut x: u64 = 0 ;
228+
229+ let mut x_ref = & mut x;
230+ let x_ref_ref = & mut x_ref;
231+
232+ * * x_ref_ref = 20 ;
233+
234+ proof { resolve( x_ref_ref) ; }
235+
236+ assert( has_resolved( x_ref) ) ; // FAILS
237+
238+ * x_ref = 30 ;
239+ proof { resolve( x_ref) ; }
240+ }
241+ } => Err ( err) => assert_fails( err, 2 )
242+ }
0 commit comments