@@ -11,7 +11,6 @@ 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 ;
1514use core:: mem:: { ManuallyDrop , SizedTypeProperties } ;
1615use core:: ops:: { Index , IndexMut , Range , RangeBounds } ;
1716use core:: ptr;
@@ -103,8 +102,7 @@ pub struct VecDeque<
103102 // if `len == 0`, the exact value of `head` is unimportant.
104103 // if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`.
105104 len : usize ,
106- buf : RawVec < A > ,
107- _marker : PhantomData < T > ,
105+ buf : RawVec < T , A > ,
108106}
109107
110108#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -128,24 +126,11 @@ impl<T: Clone, A: Allocator + Clone> Clone for VecDeque<T, A> {
128126#[ stable( feature = "rust1" , since = "1.0.0" ) ]
129127unsafe impl < #[ may_dangle] T , A : Allocator > Drop for VecDeque < T , A > {
130128 fn drop ( & mut self ) {
131- use core:: alloc:: Layout ;
132-
133- struct Guard < ' a , A : Allocator > {
134- buf : & ' a mut RawVec < A > ,
135- layout : Layout ,
136- }
137-
138- impl < A : Allocator > Drop for Guard < ' _ , A > {
139- fn drop ( & mut self ) {
140- self . buf . drop ( self . layout ) ;
141- }
142- }
143-
144129 /// Runs the destructor for all items in the slice when it gets dropped (normally or
145130 /// during unwinding).
146- struct Dropper < T > ( * mut [ T ] ) ;
131+ struct Dropper < ' a , T > ( & ' a mut [ T ] ) ;
147132
148- impl < T > Drop for Dropper < T > {
133+ impl < ' a , T > Drop for Dropper < ' a , T > {
149134 fn drop ( & mut self ) {
150135 unsafe {
151136 ptr:: drop_in_place ( self . 0 ) ;
@@ -154,16 +139,12 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque<T, A> {
154139 }
155140
156141 let ( front, back) = self . as_mut_slices ( ) ;
157- let front = front as * mut [ T ] ;
158- let back = back as * mut [ T ] ;
159-
160- let _guard = Guard { buf : & mut self . buf , layout : T :: LAYOUT } ;
161-
162142 unsafe {
163143 let _back_dropper = Dropper ( back) ;
164144 // use drop for [T]
165145 ptr:: drop_in_place ( front) ;
166146 }
147+ // RawVec handles deallocation
167148 }
168149}
169150
@@ -564,7 +545,7 @@ impl<T> VecDeque<T> {
564545 #[ must_use]
565546 pub const fn new ( ) -> VecDeque < T > {
566547 // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
567- VecDeque { head : 0 , len : 0 , buf : RawVec :: new :: < T > ( ) , _marker : PhantomData }
548+ VecDeque { head : 0 , len : 0 , buf : RawVec :: NEW }
568549 }
569550
570551 /// Creates an empty deque with space for at least `capacity` elements.
@@ -604,12 +585,7 @@ impl<T> VecDeque<T> {
604585 #[ inline]
605586 #[ unstable( feature = "try_with_capacity" , issue = "91913" ) ]
606587 pub fn try_with_capacity ( capacity : usize ) -> Result < VecDeque < T > , TryReserveError > {
607- Ok ( VecDeque {
608- head : 0 ,
609- len : 0 ,
610- buf : RawVec :: try_with_capacity_in ( capacity, Global , T :: LAYOUT ) ?,
611- _marker : PhantomData ,
612- } )
588+ Ok ( VecDeque { head : 0 , len : 0 , buf : RawVec :: try_with_capacity_in ( capacity, Global ) ? } )
613589 }
614590}
615591
@@ -626,12 +602,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
626602 #[ inline]
627603 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
628604 pub const fn new_in ( alloc : A ) -> VecDeque < T , A > {
629- VecDeque {
630- head : 0 ,
631- len : 0 ,
632- buf : RawVec :: new_in ( alloc, core:: mem:: align_of :: < T > ( ) ) ,
633- _marker : PhantomData ,
634- }
605+ VecDeque { head : 0 , len : 0 , buf : RawVec :: new_in ( alloc) }
635606 }
636607
637608 /// Creates an empty deque with space for at least `capacity` elements.
@@ -645,12 +616,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
645616 /// ```
646617 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
647618 pub fn with_capacity_in ( capacity : usize , alloc : A ) -> VecDeque < T , A > {
648- VecDeque {
649- head : 0 ,
650- len : 0 ,
651- buf : RawVec :: with_capacity_in ( capacity, alloc, T :: LAYOUT ) ,
652- _marker : PhantomData ,
653- }
619+ VecDeque { head : 0 , len : 0 , buf : RawVec :: with_capacity_in ( capacity, alloc) }
654620 }
655621
656622 /// Creates a `VecDeque` from a raw allocation, when the initialized
@@ -681,7 +647,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
681647 head : initialized. start ,
682648 len : initialized. end . unchecked_sub ( initialized. start ) ,
683649 buf : RawVec :: from_raw_parts_in ( ptr, capacity, alloc) ,
684- _marker : PhantomData ,
685650 }
686651 }
687652 }
@@ -788,7 +753,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
788753 #[ inline]
789754 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
790755 pub fn capacity ( & self ) -> usize {
791- self . buf . capacity ( core :: mem :: size_of :: < T > ( ) )
756+ if T :: IS_ZST { usize :: MAX } else { self . buf . capacity ( ) }
792757 }
793758
794759 /// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
@@ -819,7 +784,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
819784 let old_cap = self . capacity ( ) ;
820785
821786 if new_cap > old_cap {
822- self . buf . reserve_exact ( self . len , additional, T :: LAYOUT ) ;
787+ self . buf . reserve_exact ( self . len , additional) ;
823788 unsafe {
824789 self . handle_capacity_increase ( old_cap) ;
825790 }
@@ -850,7 +815,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
850815 if new_cap > old_cap {
851816 // we don't need to reserve_exact(), as the size doesn't have
852817 // to be a power of 2.
853- self . buf . reserve ( self . len , additional, T :: LAYOUT ) ;
818+ self . buf . reserve ( self . len , additional) ;
854819 unsafe {
855820 self . handle_capacity_increase ( old_cap) ;
856821 }
@@ -901,7 +866,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
901866 let old_cap = self . capacity ( ) ;
902867
903868 if new_cap > old_cap {
904- self . buf . try_reserve_exact ( self . len , additional, T :: LAYOUT ) ?;
869+ self . buf . try_reserve_exact ( self . len , additional) ?;
905870 unsafe {
906871 self . handle_capacity_increase ( old_cap) ;
907872 }
@@ -949,7 +914,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
949914 let old_cap = self . capacity ( ) ;
950915
951916 if new_cap > old_cap {
952- self . buf . try_reserve ( self . len , additional, T :: LAYOUT ) ?;
917+ self . buf . try_reserve ( self . len , additional) ?;
953918 unsafe {
954919 self . handle_capacity_increase ( old_cap) ;
955920 }
@@ -1091,7 +1056,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
10911056
10921057 let guard = Guard { deque : self , old_head, target_cap } ;
10931058
1094- guard. deque . buf . shrink_to_fit ( target_cap, T :: LAYOUT ) ;
1059+ guard. deque . buf . shrink_to_fit ( target_cap) ;
10951060
10961061 // Don't drop the guard if we didn't unwind.
10971062 mem:: forget ( guard) ;
@@ -2196,7 +2161,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
21962161 // buffer without it being full emerge
21972162 debug_assert ! ( self . is_full( ) ) ;
21982163 let old_cap = self . capacity ( ) ;
2199- self . buf . grow_one ( T :: LAYOUT ) ;
2164+ self . buf . grow_one ( ) ;
22002165 unsafe {
22012166 self . handle_capacity_increase ( old_cap) ;
22022167 }
@@ -2985,12 +2950,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
29852950 #[ inline]
29862951 fn from ( other : Vec < T , A > ) -> Self {
29872952 let ( ptr, len, cap, alloc) = other. into_raw_parts_with_alloc ( ) ;
2988- Self {
2989- head : 0 ,
2990- len,
2991- buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } ,
2992- _marker : PhantomData ,
2993- }
2953+ Self { head : 0 , len, buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } }
29942954 }
29952955}
29962956
@@ -3030,7 +2990,7 @@ impl<T, A: Allocator> From<VecDeque<T, A>> for Vec<T, A> {
30302990
30312991 unsafe {
30322992 let other = ManuallyDrop :: new ( other) ;
3033- let buf: * mut T = other. buf . ptr ( ) ;
2993+ let buf = other. buf . ptr ( ) ;
30342994 let len = other. len ( ) ;
30352995 let cap = other. capacity ( ) ;
30362996 let alloc = ptr:: read ( other. allocator ( ) ) ;
0 commit comments