@@ -1176,15 +1176,16 @@ where
1176
1176
1177
1177
// just remove the node if the value is the one we expected at method call
1178
1178
if observed_value. map ( |ov| ov == ev) . unwrap_or ( true ) {
1179
+ // we remember the old value so that we can return it and mark it for deletion below
1180
+ old_val = Some ( ev) ;
1181
+
1179
1182
// found the node but we have a new value to replace the old one
1180
1183
if let Some ( nv) = new_value {
1181
1184
n. value . store ( Owned :: new ( nv) , Ordering :: SeqCst ) ;
1182
1185
// we are just replacing entry value and we do not want to remove the node
1183
1186
// so we stop iterating here
1184
1187
break ;
1185
1188
}
1186
- // we remember the old value so that we can return it and mark it for deletion below
1187
- old_val = Some ( ev) ;
1188
1189
// remove the BinEntry containing the removed key value pair from the bucket
1189
1190
if !pred. is_null ( ) {
1190
1191
// either by changing the pointer of the previous BinEntry, if present
@@ -1701,7 +1702,7 @@ fn replace_existing() {
1701
1702
let guard = epoch:: pin ( ) ;
1702
1703
map. insert ( 42 , 42 , & guard) ;
1703
1704
let old = map. replace_node ( & 42 , Some ( 10 ) , None , & guard) ;
1704
- assert ! ( old. is_none ( ) ) ;
1705
+ assert_eq ! ( old, Some ( & 42 ) ) ;
1705
1706
assert_eq ! ( * map. get( & 42 , & guard) . unwrap( ) , 10 ) ;
1706
1707
}
1707
1708
}
@@ -1714,7 +1715,7 @@ fn replace_existing_observed_value_matching() {
1714
1715
map. insert ( 42 , 42 , & guard) ;
1715
1716
let observed_value = Shared :: from ( map. get ( & 42 , & guard) . unwrap ( ) as * const _ ) ;
1716
1717
let old = map. replace_node ( & 42 , Some ( 10 ) , Some ( observed_value) , & guard) ;
1717
- assert ! ( old. is_none ( ) ) ;
1718
+ assert_eq ! ( old, Some ( & 42 ) ) ;
1718
1719
assert_eq ! ( * map. get( & 42 , & guard) . unwrap( ) , 10 ) ;
1719
1720
}
1720
1721
}
0 commit comments