@@ -11,6 +11,7 @@ use core::cmp::{self, Ordering};
11
11
use core:: fmt;
12
12
use core:: hash:: { Hash , Hasher } ;
13
13
use core:: iter:: { repeat_n, repeat_with, ByRefSized } ;
14
+ use core:: marker:: PhantomData ;
14
15
use core:: mem:: { ManuallyDrop , SizedTypeProperties } ;
15
16
use core:: ops:: { Index , IndexMut , Range , RangeBounds } ;
16
17
use core:: ptr;
@@ -103,6 +104,7 @@ pub struct VecDeque<
103
104
// if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`.
104
105
len : usize ,
105
106
buf : RawVec < T , A > ,
107
+ _marker : PhantomData < T > ,
106
108
}
107
109
108
110
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -139,6 +141,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque<T, A> {
139
141
}
140
142
141
143
let ( front, back) = self . as_mut_slices ( ) ;
144
+
142
145
unsafe {
143
146
let _back_dropper = Dropper ( back) ;
144
147
// use drop for [T]
@@ -559,7 +562,7 @@ impl<T> VecDeque<T> {
559
562
#[ must_use]
560
563
pub const fn new ( ) -> VecDeque < T > {
561
564
// FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
562
- VecDeque { head : 0 , len : 0 , buf : RawVec :: NEW }
565
+ VecDeque { head : 0 , len : 0 , buf : RawVec :: new ( ) , _marker : PhantomData }
563
566
}
564
567
565
568
/// Creates an empty deque with space for at least `capacity` elements.
@@ -599,7 +602,12 @@ impl<T> VecDeque<T> {
599
602
#[ inline]
600
603
#[ unstable( feature = "try_with_capacity" , issue = "91913" ) ]
601
604
pub fn try_with_capacity ( capacity : usize ) -> Result < VecDeque < T > , TryReserveError > {
602
- Ok ( VecDeque { head : 0 , len : 0 , buf : RawVec :: try_with_capacity_in ( capacity, Global ) ? } )
605
+ Ok ( VecDeque {
606
+ head : 0 ,
607
+ len : 0 ,
608
+ buf : RawVec :: try_with_capacity_in ( capacity, Global ) ?,
609
+ _marker : PhantomData ,
610
+ } )
603
611
}
604
612
}
605
613
@@ -616,7 +624,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
616
624
#[ inline]
617
625
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
618
626
pub const fn new_in ( alloc : A ) -> VecDeque < T , A > {
619
- VecDeque { head : 0 , len : 0 , buf : RawVec :: new_in ( alloc) }
627
+ VecDeque {
628
+ head : 0 ,
629
+ len : 0 ,
630
+ buf : RawVec :: new_in ( alloc, core:: mem:: align_of :: < T > ( ) ) ,
631
+ _marker : PhantomData ,
632
+ }
620
633
}
621
634
622
635
/// Creates an empty deque with space for at least `capacity` elements.
@@ -630,7 +643,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
630
643
/// ```
631
644
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
632
645
pub fn with_capacity_in ( capacity : usize , alloc : A ) -> VecDeque < T , A > {
633
- VecDeque { head : 0 , len : 0 , buf : RawVec :: with_capacity_in ( capacity, alloc) }
646
+ VecDeque {
647
+ head : 0 ,
648
+ len : 0 ,
649
+ buf : RawVec :: with_capacity_in ( capacity, alloc) ,
650
+ _marker : PhantomData ,
651
+ }
634
652
}
635
653
636
654
/// Creates a `VecDeque` from a raw allocation, when the initialized
@@ -661,6 +679,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
661
679
head : initialized. start ,
662
680
len : initialized. end . unchecked_sub ( initialized. start ) ,
663
681
buf : RawVec :: from_raw_parts_in ( ptr, capacity, alloc) ,
682
+ _marker : PhantomData ,
664
683
}
665
684
}
666
685
}
@@ -767,7 +786,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
767
786
#[ inline]
768
787
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
769
788
pub fn capacity ( & self ) -> usize {
770
- if T :: IS_ZST { usize :: MAX } else { self . buf . capacity ( ) }
789
+ self . buf . capacity ( )
771
790
}
772
791
773
792
/// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
@@ -2980,7 +2999,12 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
2980
2999
#[ inline]
2981
3000
fn from ( other : Vec < T , A > ) -> Self {
2982
3001
let ( ptr, len, cap, alloc) = other. into_raw_parts_with_alloc ( ) ;
2983
- Self { head : 0 , len, buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } }
3002
+ Self {
3003
+ head : 0 ,
3004
+ len,
3005
+ buf : unsafe { RawVec :: from_raw_parts_in ( ptr, cap, alloc) } ,
3006
+ _marker : PhantomData ,
3007
+ }
2984
3008
}
2985
3009
}
2986
3010
@@ -3020,7 +3044,7 @@ impl<T, A: Allocator> From<VecDeque<T, A>> for Vec<T, A> {
3020
3044
3021
3045
unsafe {
3022
3046
let other = ManuallyDrop :: new ( other) ;
3023
- let buf = other. buf . ptr ( ) ;
3047
+ let buf: * mut T = other. buf . ptr ( ) ;
3024
3048
let len = other. len ( ) ;
3025
3049
let cap = other. capacity ( ) ;
3026
3050
let alloc = ptr:: read ( other. allocator ( ) ) ;
0 commit comments