@@ -6,13 +6,14 @@ use crate::fmt::Debug;
66use crate :: rc:: Rc ;
77use crate :: string:: { String , ToString } ;
88use crate :: vec:: Vec ;
9+ use std:: cmp:: Ordering ;
910use std:: convert:: TryFrom ;
1011use std:: iter:: { self , FromIterator } ;
1112use std:: mem;
1213use std:: ops:: Bound :: { self , Excluded , Included , Unbounded } ;
1314use std:: ops:: RangeBounds ;
1415use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
15- use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
16+ use std:: sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ;
1617
1718mod ord_chaos;
1819use ord_chaos:: { Cyclic3 , Governed , Governor } ;
@@ -56,24 +57,23 @@ impl<K, V> BTreeMap<K, V> {
5657 assert ! ( root_node. ascend( ) . is_err( ) ) ;
5758 root_node. assert_back_pointers ( ) ;
5859
59- // Check consistenty of `length` and some of the navigation .
60+ // Check consistency of `length` with what navigation code encounters .
6061 assert_eq ! ( self . length, root_node. calc_length( ) ) ;
61- assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
6262
6363 // Lastly, check the invariant causing the least harm.
6464 root_node. assert_min_len ( if root_node. height ( ) > 0 { 1 } else { 0 } ) ;
6565 } else {
66- // Check consistenty of `length` and some of the navigation.
6766 assert_eq ! ( self . length, 0 ) ;
68- assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
6967 }
68+
69+ // Check that `assert_strictly_ascending` will encounter all keys.
70+ assert_eq ! ( self . length, self . keys( ) . count( ) ) ;
7071 }
7172
7273 // Panics if the map is corrupted or if the keys are not in strictly
7374 // 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.
7777 fn check ( & self )
7878 where
7979 K : Debug + Ord ,
@@ -879,6 +879,7 @@ mod test_drain_filter {
879879 map. check ( ) ;
880880 }
881881
882+ // Explicitly consumes the iterator, where most test cases drop it instantly.
882883 #[ test]
883884 fn consumed_keeping_all ( ) {
884885 let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -887,6 +888,7 @@ mod test_drain_filter {
887888 map. check ( ) ;
888889 }
889890
891+ // Explicitly consumes the iterator, where most test cases drop it instantly.
890892 #[ test]
891893 fn consumed_removing_all ( ) {
892894 let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -896,15 +898,7 @@ mod test_drain_filter {
896898 map. check ( ) ;
897899 }
898900
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.
908902 #[ test]
909903 fn mutating_and_keeping ( ) {
910904 let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -921,6 +915,7 @@ mod test_drain_filter {
921915 map. check ( ) ;
922916 }
923917
918+ // Explicitly consumes the iterator and modifies values through it.
924919 #[ test]
925920 fn mutating_and_removing ( ) {
926921 let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
@@ -1094,7 +1089,7 @@ mod test_drain_filter {
10941089 struct D ;
10951090 impl Drop for D {
10961091 fn drop ( & mut self ) {
1097- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 1 {
1092+ if DROPS . fetch_add ( 1 , SeqCst ) == 1 {
10981093 panic ! ( "panic in `drop`" ) ;
10991094 }
11001095 }
@@ -1105,14 +1100,14 @@ mod test_drain_filter {
11051100
11061101 catch_unwind ( move || {
11071102 drop ( map. drain_filter ( |i, _| {
1108- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1103+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
11091104 true
11101105 } ) )
11111106 } )
11121107 . unwrap_err ( ) ;
11131108
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 ) ;
11161111 }
11171112
11181113 #[ test]
@@ -1123,7 +1118,7 @@ mod test_drain_filter {
11231118 struct D ;
11241119 impl Drop for D {
11251120 fn drop ( & mut self ) {
1126- DROPS . fetch_add ( 1 , Ordering :: SeqCst ) ;
1121+ DROPS . fetch_add ( 1 , SeqCst ) ;
11271122 }
11281123 }
11291124
@@ -1132,7 +1127,7 @@ mod test_drain_filter {
11321127
11331128 catch_unwind ( AssertUnwindSafe ( || {
11341129 drop ( map. drain_filter ( |i, _| {
1135- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1130+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
11361131 match i {
11371132 0 => true ,
11381133 _ => panic ! ( ) ,
@@ -1141,8 +1136,8 @@ mod test_drain_filter {
11411136 } ) )
11421137 . unwrap_err ( ) ;
11431138
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 ) ;
11461141 assert_eq ! ( map. len( ) , 2 ) ;
11471142 assert_eq ! ( map. first_entry( ) . unwrap( ) . key( ) , & 4 ) ;
11481143 assert_eq ! ( map. last_entry( ) . unwrap( ) . key( ) , & 8 ) ;
@@ -1158,7 +1153,7 @@ mod test_drain_filter {
11581153 struct D ;
11591154 impl Drop for D {
11601155 fn drop ( & mut self ) {
1161- DROPS . fetch_add ( 1 , Ordering :: SeqCst ) ;
1156+ DROPS . fetch_add ( 1 , SeqCst ) ;
11621157 }
11631158 }
11641159
@@ -1167,7 +1162,7 @@ mod test_drain_filter {
11671162
11681163 {
11691164 let mut it = map. drain_filter ( |i, _| {
1170- PREDS . fetch_add ( 1usize << i, Ordering :: SeqCst ) ;
1165+ PREDS . fetch_add ( 1usize << i, SeqCst ) ;
11711166 match i {
11721167 0 => true ,
11731168 _ => panic ! ( ) ,
@@ -1180,8 +1175,8 @@ mod test_drain_filter {
11801175 assert ! ( matches!( result, Ok ( None ) ) ) ;
11811176 }
11821177
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 ) ;
11851180 assert_eq ! ( map. len( ) , 2 ) ;
11861181 assert_eq ! ( map. first_entry( ) . unwrap( ) . key( ) , & 4 ) ;
11871182 assert_eq ! ( map. last_entry( ) . unwrap( ) . key( ) , & 8 ) ;
@@ -1315,8 +1310,6 @@ fn test_zst() {
13151310// undefined.
13161311#[ test]
13171312fn test_bad_zst ( ) {
1318- use std:: cmp:: Ordering ;
1319-
13201313 #[ derive( Clone , Copy , Debug ) ]
13211314 struct Bad ;
13221315
@@ -1763,7 +1756,7 @@ fn test_append_drop_leak() {
17631756
17641757 impl Drop for D {
17651758 fn drop ( & mut self ) {
1766- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 0 {
1759+ if DROPS . fetch_add ( 1 , SeqCst ) == 0 {
17671760 panic ! ( "panic in `drop`" ) ;
17681761 }
17691762 }
@@ -1779,7 +1772,7 @@ fn test_append_drop_leak() {
17791772
17801773 catch_unwind ( move || left. append ( & mut right) ) . unwrap_err ( ) ;
17811774
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
17831776}
17841777
17851778#[ test]
@@ -1894,7 +1887,7 @@ fn test_into_iter_drop_leak_height_0() {
18941887
18951888 impl Drop for D {
18961889 fn drop ( & mut self ) {
1897- if DROPS . fetch_add ( 1 , Ordering :: SeqCst ) == 3 {
1890+ if DROPS . fetch_add ( 1 , SeqCst ) == 3 {
18981891 panic ! ( "panic in `drop`" ) ;
18991892 }
19001893 }
@@ -1909,7 +1902,7 @@ fn test_into_iter_drop_leak_height_0() {
19091902
19101903 catch_unwind ( move || drop ( map. into_iter ( ) ) ) . unwrap_err ( ) ;
19111904
1912- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , 5 ) ;
1905+ assert_eq ! ( DROPS . load( SeqCst ) , 5 ) ;
19131906}
19141907
19151908#[ test]
@@ -1921,18 +1914,18 @@ fn test_into_iter_drop_leak_height_1() {
19211914 struct D ;
19221915 impl Drop for D {
19231916 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 ) {
19251918 panic ! ( "panic in `drop`" ) ;
19261919 }
19271920 }
19281921 }
19291922
19301923 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 ) ;
19331926 let map: BTreeMap < _ , _ > = ( 0 ..size) . map ( |i| ( i, D ) ) . collect ( ) ;
19341927 catch_unwind ( move || drop ( map. into_iter ( ) ) ) . unwrap_err ( ) ;
1935- assert_eq ! ( DROPS . load( Ordering :: SeqCst ) , size) ;
1928+ assert_eq ! ( DROPS . load( SeqCst ) , size) ;
19361929 }
19371930}
19381931
0 commit comments