File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2160,6 +2160,35 @@ mod tests {
21602160 assert_eq ! ( v. map_in_place( |_| ZeroSized ) , [ ZeroSized , ZeroSized ] ) ;
21612161 }
21622162
2163+ #[ test]
2164+ fn test_map_in_place_zero_drop_count ( ) {
2165+ use std:: sync:: atomic;
2166+ use std:: sync:: atomic:: AtomicUint ;
2167+
2168+ #[ deriving( Clone , PartialEq , Show ) ]
2169+ struct Nothing ;
2170+ impl Drop for Nothing { fn drop ( & mut self ) { } }
2171+
2172+ #[ deriving( Clone , PartialEq , Show ) ]
2173+ struct ZeroSized ;
2174+ impl Drop for ZeroSized {
2175+ fn drop ( & mut self ) {
2176+ DROP_COUNTER . fetch_add ( 1 , atomic:: Relaxed ) ;
2177+ }
2178+ }
2179+ const NUM_ELEMENTS : uint = 2 ;
2180+ static DROP_COUNTER : AtomicUint = atomic:: INIT_ATOMIC_UINT ;
2181+
2182+ let v = Vec :: from_elem ( NUM_ELEMENTS , Nothing ) ;
2183+
2184+ DROP_COUNTER . store ( 0 , atomic:: Relaxed ) ;
2185+
2186+ let v = v. map_in_place ( |_| ZeroSized ) ;
2187+ assert_eq ! ( DROP_COUNTER . load( atomic:: Relaxed ) , 0 ) ;
2188+ drop ( v) ;
2189+ assert_eq ! ( DROP_COUNTER . load( atomic:: Relaxed ) , NUM_ELEMENTS ) ;
2190+ }
2191+
21632192 #[ test]
21642193 fn test_move_items ( ) {
21652194 let vec = vec ! [ 1 , 2 , 3 ] ;
You can’t perform that action at this time.
0 commit comments