@@ -59,22 +59,22 @@ fn double_imm_borrow() {
59
59
fn no_mut_then_imm_borrow ( ) {
60
60
let x = RefCell :: new ( 0 ) ;
61
61
let _b1 = x. borrow_mut ( ) ;
62
- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Writing ) ;
62
+ assert ! ( x. try_borrow ( ) . is_err ( ) ) ;
63
63
}
64
64
65
65
#[ test]
66
66
fn no_imm_then_borrow_mut ( ) {
67
67
let x = RefCell :: new ( 0 ) ;
68
68
let _b1 = x. borrow ( ) ;
69
- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Reading ) ;
69
+ assert ! ( x. try_borrow_mut ( ) . is_err ( ) ) ;
70
70
}
71
71
72
72
#[ test]
73
73
fn no_double_borrow_mut ( ) {
74
74
let x = RefCell :: new ( 0 ) ;
75
- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Unused ) ;
75
+ assert ! ( x. try_borrow ( ) . is_ok ( ) ) ;
76
76
let _b1 = x. borrow_mut ( ) ;
77
- assert_eq ! ( x. borrow_state ( ) , BorrowState :: Writing ) ;
77
+ assert ! ( x. try_borrow ( ) . is_err ( ) ) ;
78
78
}
79
79
80
80
#[ test]
@@ -102,7 +102,8 @@ fn double_borrow_single_release_no_borrow_mut() {
102
102
{
103
103
let _b2 = x. borrow ( ) ;
104
104
}
105
- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
105
+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
106
+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
106
107
}
107
108
108
109
#[ test]
@@ -119,30 +120,38 @@ fn ref_clone_updates_flag() {
119
120
let x = RefCell :: new ( 0 ) ;
120
121
{
121
122
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( ) ) ;
123
125
{
124
126
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( ) ) ;
126
129
}
127
- assert_eq ! ( x. borrow_state( ) , BorrowState :: Reading ) ;
130
+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
131
+ assert ! ( x. try_borrow_mut( ) . is_err( ) ) ;
128
132
}
129
- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
133
+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
134
+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
130
135
}
131
136
132
137
#[ test]
133
138
fn ref_map_does_not_update_flag ( ) {
134
139
let x = RefCell :: new ( Some ( 5 ) ) ;
135
140
{
136
141
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( ) ) ;
138
144
{
139
145
let b2: Ref < u32 > = Ref :: map ( b1, |o| o. as_ref ( ) . unwrap ( ) ) ;
140
146
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( ) ) ;
142
149
}
143
- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
150
+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
151
+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
144
152
}
145
- assert_eq ! ( x. borrow_state( ) , BorrowState :: Unused ) ;
153
+ assert ! ( x. try_borrow( ) . is_ok( ) ) ;
154
+ assert ! ( x. try_borrow_mut( ) . is_ok( ) ) ;
146
155
}
147
156
148
157
#[ test]
@@ -247,5 +256,3 @@ fn refcell_ref_coercion() {
247
256
assert_eq ! ( & * coerced, comp) ;
248
257
}
249
258
}
250
-
251
-
0 commit comments