@@ -958,23 +958,35 @@ fn test_append() {
958958#[ test]
959959fn test_split_off ( ) {
960960 let mut vec = vec ! [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
961+ let orig_ptr = vec. as_ptr ( ) ;
961962 let orig_capacity = vec. capacity ( ) ;
962- let vec2 = vec. split_off ( 4 ) ;
963+
964+ let split_off = vec. split_off ( 4 ) ;
963965 assert_eq ! ( vec, [ 1 , 2 , 3 , 4 ] ) ;
964- assert_eq ! ( vec2 , [ 5 , 6 ] ) ;
966+ assert_eq ! ( split_off , [ 5 , 6 ] ) ;
965967 assert_eq ! ( vec. capacity( ) , orig_capacity) ;
968+ assert_eq ! ( vec. as_ptr( ) , orig_ptr) ;
966969}
967970
968971#[ test]
969972fn test_split_off_take_all ( ) {
970- let mut vec = vec ! [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
973+ // Allocate enough capacity that we can tell whether the split-off vector's
974+ // capacity is based on its size, or (incorrectly) on the original capacity.
975+ let mut vec = Vec :: with_capacity ( 1000 ) ;
976+ vec. extend ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
971977 let orig_ptr = vec. as_ptr ( ) ;
972978 let orig_capacity = vec. capacity ( ) ;
973- let vec2 = vec. split_off ( 0 ) ;
979+
980+ let split_off = vec. split_off ( 0 ) ;
974981 assert_eq ! ( vec, [ ] ) ;
975- assert_eq ! ( vec2 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
982+ assert_eq ! ( split_off , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
976983 assert_eq ! ( vec. capacity( ) , orig_capacity) ;
977- assert_eq ! ( vec2. as_ptr( ) , orig_ptr) ;
984+ assert_eq ! ( vec. as_ptr( ) , orig_ptr) ;
985+
986+ // The split-off vector should be newly-allocated, and should not have
987+ // stolen the original vector's allocation.
988+ assert ! ( split_off. capacity( ) < orig_capacity) ;
989+ assert_ne ! ( split_off. as_ptr( ) , orig_ptr) ;
978990}
979991
980992#[ test]
0 commit comments