@@ -11,6 +11,7 @@ use core::cmp::{self, Ordering};
1111use core:: fmt;
1212use core:: hash:: { Hash , Hasher } ;
1313use core:: iter:: { repeat_n, repeat_with, ByRefSized } ;
14+ use core:: marker:: PhantomData ;
1415use core:: mem:: { ManuallyDrop , SizedTypeProperties } ;
1516use core:: ops:: { Index , IndexMut , Range , RangeBounds } ;
1617use core:: ptr;
@@ -102,7 +103,8 @@ pub struct VecDeque<
102103 // if `len == 0`, the exact value of `head` is unimportant.
103104 // if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`.
104105 len : usize ,
105- buf : RawVec < T , A > ,
106+ buf : RawVec < A > ,
107+ _marker : PhantomData < T > ,
106108}
107109
108110#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -144,7 +146,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque<T, A> {
144146 // use drop for [T]
145147 ptr:: drop_in_place ( front) ;
146148 }
147- // RawVec handles deallocation
149+ self . buf . drop_if_needed ( T :: LAYOUT ) ;
148150 }
149151}
150152
@@ -545,7 +547,7 @@ impl<T> VecDeque<T> {
545547 #[ must_use]
546548 pub const fn new ( ) -> VecDeque < T > {
547549 // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
548- VecDeque { head : 0 , len : 0 , buf : RawVec :: NEW }
550+ VecDeque { head : 0 , len : 0 , buf : RawVec :: new :: < T > ( ) , _marker : PhantomData }
549551 }
550552
551553 /// Creates an empty deque with space for at least `capacity` elements.
@@ -585,7 +587,12 @@ impl<T> VecDeque<T> {
585587 #[ inline]
586588 #[ unstable( feature = "try_with_capacity" , issue = "91913" ) ]
587589 pub fn try_with_capacity ( capacity : usize ) -> Result < VecDeque < T > , TryReserveError > {
588- Ok ( VecDeque { head : 0 , len : 0 , buf : RawVec :: try_with_capacity_in ( capacity, Global ) ? } )
590+ Ok ( VecDeque {
591+ head : 0 ,
592+ len : 0 ,
593+ buf : RawVec :: try_with_capacity_in ( capacity, Global , T :: LAYOUT ) ?,
594+ _marker : PhantomData ,
595+ } )
589596 }
590597}
591598
@@ -602,7 +609,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
602609 #[ inline]
603610 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
604611 pub const fn new_in ( alloc : A ) -> VecDeque < T , A > {
605- VecDeque { head : 0 , len : 0 , buf : RawVec :: new_in ( alloc) }
612+ VecDeque {
613+ head : 0 ,
614+ len : 0 ,
615+ buf : RawVec :: new_in ( alloc, core:: mem:: align_of :: < T > ( ) ) ,
616+ _marker : PhantomData ,
617+ }
606618 }
607619
608620 /// Creates an empty deque with space for at least `capacity` elements.
@@ -616,7 +628,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
616628 /// ```
617629 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
618630 pub fn with_capacity_in ( capacity : usize , alloc : A ) -> VecDeque < T , A > {
619- VecDeque { head : 0 , len : 0 , buf : RawVec :: with_capacity_in ( capacity, alloc) }
631+ VecDeque {
632+ head : 0 ,
633+ len : 0 ,
634+ buf : RawVec :: with_capacity_in ( capacity, alloc, T :: LAYOUT ) ,
635+ _marker : PhantomData ,
636+ }
620637 }
621638
622639 /// Creates a `VecDeque` from a raw allocation, when the initialized
@@ -647,6 +664,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
647664 head : initialized. start ,
648665 len : initialized. end . unchecked_sub ( initialized. start ) ,
649666 buf : RawVec :: from_raw_parts_in ( ptr, capacity, alloc) ,
667+ _marker : PhantomData ,
650668 }
651669 }
652670 }
@@ -753,7 +771,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
753771 #[ inline]
754772 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
755773 pub fn capacity ( & self ) -> usize {
756- if T :: IS_ZST { usize :: MAX } else { self . buf . capacity ( ) }
774+ self . buf . capacity ( core :: mem :: size_of :: < T > ( ) )
757775 }
758776
759777 /// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
@@ -784,7 +802,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
784802 let old_cap = self . capacity ( ) ;
785803
786804 if new_cap > old_cap {
787- self . buf . reserve_exact ( self . len , additional) ;
805+ self . buf . reserve_exact ( self . len , additional, T :: LAYOUT ) ;
788806 unsafe {
789807 self . handle_capacity_increase ( old_cap) ;
790808 }
@@ -815,7 +833,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
815833 if new_cap > old_cap {
816834 // we don't need to reserve_exact(), as the size doesn't have
817835 // to be a power of 2.
818- self . buf . reserve ( self . len , additional) ;
836+ self . buf . reserve ( self . len , additional, T :: LAYOUT ) ;
819837 unsafe {
820838 self . handle_capacity_increase ( old_cap) ;
821839 }
@@ -866,7 +884,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
866884 let old_cap = self . capacity ( ) ;
867885
868886 if new_cap > old_cap {
869- self . buf . try_reserve_exact ( self . len , additional) ?;
887+ self . buf . try_reserve_exact ( self . len , additional, T :: LAYOUT ) ?;
870888 unsafe {
871889 self . handle_capacity_increase ( old_cap) ;
872890 }
@@ -914,7 +932,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
914932 let old_cap = self . capacity ( ) ;
915933
916934 if new_cap > old_cap {
917- self . buf . try_reserve ( self . len , additional) ?;
935+ self . buf . try_reserve ( self . len , additional, T :: LAYOUT ) ?;
918936 unsafe {
919937 self . handle_capacity_increase ( old_cap) ;
920938 }
@@ -1056,7 +1074,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
10561074
10571075 let guard = Guard { deque : self , old_head, target_cap } ;
10581076
1059- guard. deque . buf . shrink_to_fit ( target_cap) ;
1077+ guard. deque . buf . shrink_to_fit ( target_cap, T :: LAYOUT ) ;
10601078
10611079 // Don't drop the guard if we didn't unwind.
10621080 mem:: forget ( guard) ;
@@ -2161,7 +2179,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
21612179 // buffer without it being full emerge
21622180 debug_assert ! ( self . is_full( ) ) ;
21632181 let old_cap = self . capacity ( ) ;
2164- self . buf . grow_one ( ) ;
2182+ self . buf . grow_one ( T :: LAYOUT ) ;
21652183 unsafe {
21662184 self . handle_capacity_increase ( old_cap) ;
21672185 }
@@ -2950,7 +2968,12 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
29502968 #[ inline]
29512969 fn from ( other : Vec < T , A > ) -> Self {
29522970 let ( ptr, len, cap, alloc) = other. into_raw_parts_with_alloc ( ) ;
2953- Self { head : 0 , len, buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } }
2971+ Self {
2972+ head : 0 ,
2973+ len,
2974+ buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } ,
2975+ _marker : PhantomData ,
2976+ }
29542977 }
29552978}
29562979
@@ -2990,7 +3013,7 @@ impl<T, A: Allocator> From<VecDeque<T, A>> for Vec<T, A> {
29903013
29913014 unsafe {
29923015 let other = ManuallyDrop :: new ( other) ;
2993- let buf = other. buf . ptr ( ) ;
3016+ let buf: * mut T = other. buf . ptr ( ) ;
29943017 let len = other. len ( ) ;
29953018 let cap = other. capacity ( ) ;
29963019 let alloc = ptr:: read ( other. allocator ( ) ) ;
0 commit comments