@@ -1741,22 +1741,32 @@ fn test_resize_keeps_reserved_space_from_item() {
17411741fn test_collect_from_into_iter_keeps_allocation ( ) {
17421742 let mut v = Vec :: with_capacity ( 13 ) ;
17431743 v. extend ( 0 ..7 ) ;
1744- check ( v. into_iter ( ) ) ;
1744+ check ( v. as_ptr ( ) , v . last ( ) . unwrap ( ) , v . into_iter ( ) ) ;
17451745
17461746 let mut v = VecDeque :: with_capacity ( 13 ) ;
17471747 v. extend ( 0 ..7 ) ;
1748- check ( v. into_iter ( ) ) ;
1748+ check ( & v [ 0 ] , & v [ v . len ( ) - 1 ] , v. into_iter ( ) ) ;
17491749
1750- fn check ( mut it : impl Iterator < Item = i32 > ) {
1750+ fn check ( buf : * const i32 , last : * const i32 , mut it : impl Iterator < Item = i32 > ) {
17511751 assert_eq ! ( it. next( ) , Some ( 0 ) ) ;
17521752 assert_eq ! ( it. next( ) , Some ( 1 ) ) ;
1753+
17531754 let mut v: VecDeque < i32 > = it. collect ( ) ;
17541755 assert_eq ! ( v. capacity( ) , 13 ) ;
1756+ assert_eq ! ( v. as_slices( ) . 0 . as_ptr( ) , buf. wrapping_add( 2 ) ) ;
1757+ assert_eq ! ( & v[ v. len( ) - 1 ] as * const _, last) ;
1758+
17551759 assert_eq ! ( v. as_slices( ) , ( [ 2 , 3 , 4 , 5 , 6 ] . as_slice( ) , [ ] . as_slice( ) ) ) ;
17561760 v. push_front ( 7 ) ;
17571761 assert_eq ! ( v. as_slices( ) , ( [ 7 , 2 , 3 , 4 , 5 , 6 ] . as_slice( ) , [ ] . as_slice( ) ) ) ;
17581762 v. push_front ( 8 ) ;
17591763 assert_eq ! ( v. as_slices( ) , ( [ 8 , 7 , 2 , 3 , 4 , 5 , 6 ] . as_slice( ) , [ ] . as_slice( ) ) ) ;
1764+
1765+ // Now that we've adding thing in place of the two that we removed from
1766+ // the front of the iterator, we're back to matching the buffer pointer.
1767+ assert_eq ! ( v. as_slices( ) . 0 . as_ptr( ) , buf) ;
1768+ assert_eq ! ( & v[ v. len( ) - 1 ] as * const _, last) ;
1769+
17601770 v. push_front ( 9 ) ;
17611771 assert_eq ! ( v. as_slices( ) , ( [ 9 ] . as_slice( ) , [ 8 , 7 , 2 , 3 , 4 , 5 , 6 ] . as_slice( ) ) ) ;
17621772 assert_eq ! ( v. capacity( ) , 13 ) ;
0 commit comments