@@ -59,22 +59,22 @@ fn double_imm_borrow() {
5959fn no_mut_then_imm_borrow ( ) {
6060 let x = RefCell :: new ( 0 ) ;
6161 let _b1 = x. borrow_mut ( ) ;
62- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Writing ) ;
62+ assert ! ( x. try_borrow ( ) . is_err ( ) ) ;
6363}
6464
6565#[ test]
6666fn no_imm_then_borrow_mut ( ) {
6767 let x = RefCell :: new ( 0 ) ;
6868 let _b1 = x. borrow ( ) ;
69- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Reading ) ;
69+ assert ! ( x. try_borrow_mut ( ) . is_err ( ) ) ;
7070}
7171
7272#[ test]
7373fn no_double_borrow_mut ( ) {
7474 let x = RefCell :: new ( 0 ) ;
75- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Unused ) ;
75+ assert ! ( x. try_borrow ( ) . is_ok ( ) ) ;
7676 let _b1 = x. borrow_mut ( ) ;
77- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Writing ) ;
77+ assert ! ( x. try_borrow ( ) . is_err ( ) ) ;
7878}
7979
8080#[ test]
@@ -102,7 +102,8 @@ fn double_borrow_single_release_no_borrow_mut() {
102102 {
103103 let _b2 = x. borrow ( ) ;
104104 }
105- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
105+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
106+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
106107}
107108
108109#[ test]
@@ -119,30 +120,38 @@ fn ref_clone_updates_flag() {
119120 let x = RefCell :: new ( 0 ) ;
120121 {
121122 let b1 = x. borrow ( ) ;
122- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
123+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
124+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
123125 {
124126 let _b2 = Ref :: clone ( & b1) ;
125- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
127+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
128+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
126129 }
127- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
130+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
131+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
128132 }
129- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
133+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
134+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
130135}
131136
132137#[ test]
133138fn ref_map_does_not_update_flag ( ) {
134139 let x = RefCell :: new ( Some ( 5 ) ) ;
135140 {
136141 let b1: Ref < Option < u32 > > = x. borrow ( ) ;
137- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
142+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
143+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
138144 {
139145 let b2: Ref < u32 > = Ref :: map ( b1, |o| o. as_ref ( ) . unwrap ( ) ) ;
140146 assert_eq ! ( * b2, 5 ) ;
141- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
147+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
148+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
142149 }
143- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
150+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
151+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
144152 }
145- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
153+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
154+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
146155}
147156
148157#[ test]
@@ -247,5 +256,3 @@ fn refcell_ref_coercion() {
247256 assert_eq ! ( & * coerced, comp) ;
248257 }
249258}
250-
251-
0 commit comments