@@ -6,13 +6,14 @@ use crate::fmt::Debug;
6
6
use crate :: rc:: Rc ;
7
7
use crate :: string:: { String , ToString } ;
8
8
use crate :: vec:: Vec ;
9
+ use std:: cmp:: Ordering ;
9
10
use std:: convert:: TryFrom ;
10
11
use std:: iter:: { self , FromIterator } ;
11
12
use std:: mem;
12
13
use std:: ops:: Bound :: { self , Excluded , Included , Unbounded } ;
13
14
use std:: ops:: RangeBounds ;
14
15
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
15
- use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
16
+ use std:: sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ;
16
17
17
18
mod ord_chaos;
18
19
use ord_chaos:: { Cyclic3 , Governed , Governor } ;
@@ -56,24 +57,23 @@ impl<K, V> BTreeMap<K, V> {
56
57
assert ! ( root_node. ascend( ) . is_err( ) ) ;
57
58
root_node. assert_back_pointers ( ) ;
58
59
59
- // Check consistenty of `length` and some of the navigation .
60
+ // Check consistency of `length` with what navigation code encounters .
60
61
assert_eq ! ( self . length, root_node. calc_length( ) ) ;
61
- assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
62
62
63
63
// Lastly, check the invariant causing the least harm.
64
64
root_node. assert_min_len ( if root_node. height ( ) > 0 { 1 } else { 0 } ) ;
65
65
} else {
66
- // Check consistenty of `length` and some of the navigation.
67
66
assert_eq ! ( self . length, 0 ) ;
68
- assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
69
67
}
68
+
69
+ // Check that `assert_strictly_ascending` will encounter all keys.
70
+ assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
70
71
}
71
72
72
73
// Panics if the map is corrupted or if the keys are not in strictly
73
74
// ascending order, in the current opinion of the `Ord` implementation.
74
- // If the `Ord` implementation does not honor transitivity, this method
75
- // does not guarantee that all the keys are unique, just that adjacent
76
- // keys are unique.
75
+ // If the `Ord` implementation violates transitivity, this method does not
76
+ // guarantee that all keys are unique, just that adjacent keys are unique.
77
77
fn check ( & self )
78
78
where
79
79
K : Debug + Ord ,
@@ -879,6 +879,7 @@ mod test_drain_filter {
879
879
map. check ( ) ;
880
880
}
881
881
882
+ // Explicitly consumes the iterator, where most test cases drop it instantly.
882
883
#[ test]
883
884
fn consumed_keeping_all ( ) {
884
885
let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -887,6 +888,7 @@ mod test_drain_filter {
887
888
map. check ( ) ;
888
889
}
889
890
891
+ // Explicitly consumes the iterator, where most test cases drop it instantly.
890
892
#[ test]
891
893
fn consumed_removing_all ( ) {
892
894
let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -896,15 +898,7 @@ mod test_drain_filter {
896
898
map. check ( ) ;
897
899
}
898
900
899
- #[ test]
900
- fn dropped_removing_all ( ) {
901
- let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
902
- let mut map: BTreeMap < _ , _ > = pairs. collect ( ) ;
903
- map. drain_filter ( |_, _| true ) ;
904
- assert ! ( map. is_empty( ) ) ;
905
- map. check ( ) ;
906
- }
907
-
901
+ // Explicitly consumes the iterator and modifies values through it.
908
902
#[ test]
909
903
fn mutating_and_keeping ( ) {
910
904
let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -921,6 +915,7 @@ mod test_drain_filter {
921
915
map. check ( ) ;
922
916
}
923
917
918
+ // Explicitly consumes the iterator and modifies values through it.
924
919
#[ test]
925
920
fn mutating_and_removing ( ) {
926
921
let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -1094,7 +1089,7 @@ mod test_drain_filter {
1094
1089
struct D ;
1095
1090
impl Drop for D {
1096
1091
fn drop ( & mut self ) {
1097
- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 1 {
1092
+ if DROPS . fetch_add ( 1 , SeqCst ) == 1 {
1098
1093
panic ! ( "panic in `drop`" ) ;
1099
1094
}
1100
1095
}
@@ -1105,14 +1100,14 @@ mod test_drain_filter {
1105
1100
1106
1101
catch_unwind ( move || {
1107
1102
drop ( map. drain_filter ( |i, _| {
1108
- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1103
+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
1109
1104
true
1110
1105
} ) )
1111
1106
} )
1112
1107
. unwrap_err ( ) ;
1113
1108
1114
- assert_eq ! ( PREDS . load( Ordering :: SeqCst ) , 0x011 ) ;
1115
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 3 ) ;
1109
+ assert_eq ! ( PREDS . load( SeqCst ) , 0x011 ) ;
1110
+ assert_eq ! ( DROPS . load( SeqCst ) , 3 ) ;
1116
1111
}
1117
1112
1118
1113
#[ test]
@@ -1123,7 +1118,7 @@ mod test_drain_filter {
1123
1118
struct D ;
1124
1119
impl Drop for D {
1125
1120
fn drop ( & mut self ) {
1126
- DROPS . fetch_add ( 1 , Ordering :: SeqCst ) ;
1121
+ DROPS . fetch_add ( 1 , SeqCst ) ;
1127
1122
}
1128
1123
}
1129
1124
@@ -1132,7 +1127,7 @@ mod test_drain_filter {
1132
1127
1133
1128
catch_unwind ( AssertUnwindSafe ( || {
1134
1129
drop ( map. drain_filter ( |i, _| {
1135
- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1130
+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
1136
1131
match i {
1137
1132
0 => true ,
1138
1133
_ => panic ! ( ) ,
@@ -1141,8 +1136,8 @@ mod test_drain_filter {
1141
1136
} ) )
1142
1137
. unwrap_err ( ) ;
1143
1138
1144
- assert_eq ! ( PREDS . load( Ordering :: SeqCst ) , 0x011 ) ;
1145
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 1 ) ;
1139
+ assert_eq ! ( PREDS . load( SeqCst ) , 0x011 ) ;
1140
+ assert_eq ! ( DROPS . load( SeqCst ) , 1 ) ;
1146
1141
assert_eq ! ( map. len( ) , 2 ) ;
1147
1142
assert_eq ! ( map. first_entry( ) . unwrap( ) . key( ) , & 4 ) ;
1148
1143
assert_eq ! ( map. last_entry( ) . unwrap( ) . key( ) , & 8 ) ;
@@ -1158,7 +1153,7 @@ mod test_drain_filter {
1158
1153
struct D ;
1159
1154
impl Drop for D {
1160
1155
fn drop ( & mut self ) {
1161
- DROPS . fetch_add ( 1 , Ordering :: SeqCst ) ;
1156
+ DROPS . fetch_add ( 1 , SeqCst ) ;
1162
1157
}
1163
1158
}
1164
1159
@@ -1167,7 +1162,7 @@ mod test_drain_filter {
1167
1162
1168
1163
{
1169
1164
let mut it = map. drain_filter ( |i, _| {
1170
- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1165
+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
1171
1166
match i {
1172
1167
0 => true ,
1173
1168
_ => panic ! ( ) ,
@@ -1180,8 +1175,8 @@ mod test_drain_filter {
1180
1175
assert ! ( matches!( result, Ok ( None ) ) ) ;
1181
1176
}
1182
1177
1183
- assert_eq ! ( PREDS . load( Ordering :: SeqCst ) , 0x011 ) ;
1184
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 1 ) ;
1178
+ assert_eq ! ( PREDS . load( SeqCst ) , 0x011 ) ;
1179
+ assert_eq ! ( DROPS . load( SeqCst ) , 1 ) ;
1185
1180
assert_eq ! ( map. len( ) , 2 ) ;
1186
1181
assert_eq ! ( map. first_entry( ) . unwrap( ) . key( ) , & 4 ) ;
1187
1182
assert_eq ! ( map. last_entry( ) . unwrap( ) . key( ) , & 8 ) ;
@@ -1315,8 +1310,6 @@ fn test_zst() {
1315
1310
// undefined.
1316
1311
#[ test]
1317
1312
fn test_bad_zst ( ) {
1318
- use std:: cmp:: Ordering ;
1319
-
1320
1313
#[ derive( Clone , Copy , Debug ) ]
1321
1314
struct Bad ;
1322
1315
@@ -1763,7 +1756,7 @@ fn test_append_drop_leak() {
1763
1756
1764
1757
impl Drop for D {
1765
1758
fn drop ( & mut self ) {
1766
- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 0 {
1759
+ if DROPS . fetch_add ( 1 , SeqCst ) == 0 {
1767
1760
panic ! ( "panic in `drop`" ) ;
1768
1761
}
1769
1762
}
@@ -1779,7 +1772,7 @@ fn test_append_drop_leak() {
1779
1772
1780
1773
catch_unwind ( move || left. append ( & mut right) ) . unwrap_err ( ) ;
1781
1774
1782
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 4 ) ; // Rust issue #47949 ate one little piggy
1775
+ assert_eq ! ( DROPS . load( SeqCst ) , 4 ) ; // Rust issue #47949 ate one little piggy
1783
1776
}
1784
1777
1785
1778
#[ test]
@@ -1894,7 +1887,7 @@ fn test_into_iter_drop_leak_height_0() {
1894
1887
1895
1888
impl Drop for D {
1896
1889
fn drop ( & mut self ) {
1897
- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 3 {
1890
+ if DROPS . fetch_add ( 1 , SeqCst ) == 3 {
1898
1891
panic ! ( "panic in `drop`" ) ;
1899
1892
}
1900
1893
}
@@ -1909,7 +1902,7 @@ fn test_into_iter_drop_leak_height_0() {
1909
1902
1910
1903
catch_unwind ( move || drop ( map. into_iter ( ) ) ) . unwrap_err ( ) ;
1911
1904
1912
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 5 ) ;
1905
+ assert_eq ! ( DROPS . load( SeqCst ) , 5 ) ;
1913
1906
}
1914
1907
1915
1908
#[ test]
@@ -1921,18 +1914,18 @@ fn test_into_iter_drop_leak_height_1() {
1921
1914
struct D ;
1922
1915
impl Drop for D {
1923
1916
fn drop ( & mut self ) {
1924
- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == PANIC_POINT . load ( Ordering :: SeqCst ) {
1917
+ if DROPS . fetch_add ( 1 , SeqCst ) == PANIC_POINT . load ( SeqCst ) {
1925
1918
panic ! ( "panic in `drop`" ) ;
1926
1919
}
1927
1920
}
1928
1921
}
1929
1922
1930
1923
for panic_point in vec ! [ 0 , 1 , size - 2 , size - 1 ] {
1931
- DROPS . store ( 0 , Ordering :: SeqCst ) ;
1932
- PANIC_POINT . store ( panic_point, Ordering :: SeqCst ) ;
1924
+ DROPS . store ( 0 , SeqCst ) ;
1925
+ PANIC_POINT . store ( panic_point, SeqCst ) ;
1933
1926
let map: BTreeMap < _ , _ > = ( 0 ..size) . map ( |i| ( i, D ) ) . collect ( ) ;
1934
1927
catch_unwind ( move || drop ( map. into_iter ( ) ) ) . unwrap_err ( ) ;
1935
- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , size) ;
1928
+ assert_eq ! ( DROPS . load( SeqCst ) , size) ;
1936
1929
}
1937
1930
}
1938
1931
0 commit comments