@@ -1741,22 +1741,32 @@ fn test_resize_keeps_reserved_space_from_item() {
1741
1741
fn test_collect_from_into_iter_keeps_allocation ( ) {
1742
1742
let mut v = Vec :: with_capacity ( 13 ) ;
1743
1743
v. extend ( 0 ..7 ) ;
1744
- check ( v. into_iter ( ) ) ;
1744
+ check ( v. as_ptr ( ) , v . last ( ) . unwrap ( ) , v . into_iter ( ) ) ;
1745
1745
1746
1746
let mut v = VecDeque :: with_capacity ( 13 ) ;
1747
1747
v. extend ( 0 ..7 ) ;
1748
- check ( v. into_iter ( ) ) ;
1748
+ check ( & v [ 0 ] , & v [ v . len ( ) - 1 ] , v. into_iter ( ) ) ;
1749
1749
1750
- fn check ( mut it : impl Iterator < Item = i32 > ) {
1750
+ fn check ( buf : * const i32 , last : * const i32 , mut it : impl Iterator < Item = i32 > ) {
1751
1751
assert_eq ! ( it. next( ) , Some ( 0 ) ) ;
1752
1752
assert_eq ! ( it. next( ) , Some ( 1 ) ) ;
1753
+
1753
1754
let mut v: VecDeque < i32 > = it. collect ( ) ;
1754
1755
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
+
1755
1759
assert_eq ! ( v. as_slices( ) , ( [ 2 , 3 , 4 , 5 , 6 ] . as_slice( ) , [ ] . as_slice( ) ) ) ;
1756
1760
v. push_front ( 7 ) ;
1757
1761
assert_eq ! ( v. as_slices( ) , ( [ 7 , 2 , 3 , 4 , 5 , 6 ] . as_slice( ) , [ ] . as_slice( ) ) ) ;
1758
1762
v. push_front ( 8 ) ;
1759
1763
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
+
1760
1770
v. push_front ( 9 ) ;
1761
1771
assert_eq ! ( v. as_slices( ) , ( [ 9 ] . as_slice( ) , [ 8 , 7 , 2 , 3 , 4 , 5 , 6 ] . as_slice( ) ) ) ;
1762
1772
assert_eq ! ( v. capacity( ) , 13 ) ;
0 commit comments