@@ -1507,6 +1507,8 @@ impl<T> VecDeque<T> {
15071507
15081508 #[ inline]
15091509 fn is_contiguous ( & self ) -> bool {
1510+ // FIXME: Should we consider `head == 0` to mean
1511+ // that `self` is contiguous?
15101512 self . tail <= self . head
15111513 }
15121514
@@ -2236,7 +2238,7 @@ impl<T> VecDeque<T> {
22362238 if self . is_contiguous ( ) {
22372239 let tail = self . tail ;
22382240 let head = self . head ;
2239- return unsafe { & mut self . buffer_as_mut_slice ( ) [ tail..head ] } ;
2241+ return unsafe { RingSlices :: ring_slices ( self . buffer_as_mut_slice ( ) , head , tail) . 0 } ;
22402242 }
22412243
22422244 let buf = self . buf . ptr ( ) ;
@@ -2262,7 +2264,13 @@ impl<T> VecDeque<T> {
22622264 self . tail = 0 ;
22632265 self . head = len;
22642266 }
2265- } else if free >= self . head {
2267+ } else if free > self . head {
2268+ // FIXME: We currently do not consider ....ABCDEFGH
2269+ // to be contiguous because `head` would be `0` in this
2270+ // case. While we probably want to change this it
2271+ // isn't trivial as a few places expect `is_contiguous`
2272+ // to mean that we can just slice using `buf[tail..head]`.
2273+
22662274 // there is enough free space to copy the head in one go,
22672275 // this means that we first shift the tail forwards, and then
22682276 // copy the head to the correct position.
@@ -2276,7 +2284,7 @@ impl<T> VecDeque<T> {
22762284 // ...ABCDEFGH.
22772285
22782286 self . tail = self . head ;
2279- self . head = self . tail + len;
2287+ self . head = self . wrap_add ( self . tail , len) ;
22802288 }
22812289 } else {
22822290 // free is smaller than both head and tail,
@@ -2316,7 +2324,7 @@ impl<T> VecDeque<T> {
23162324
23172325 let tail = self . tail ;
23182326 let head = self . head ;
2319- unsafe { & mut self . buffer_as_mut_slice ( ) [ tail..head ] }
2327+ unsafe { RingSlices :: ring_slices ( self . buffer_as_mut_slice ( ) , head , tail) . 0 }
23202328 }
23212329
23222330 /// Rotates the double-ended queue `mid` places to the left.
@@ -3282,7 +3290,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {
32823290 let len = other. len ( ) ;
32833291 let cap = other. cap ( ) ;
32843292
3285- if other. head != 0 {
3293+ if other. tail != 0 {
32863294 ptr:: copy ( buf. add ( other. tail ) , buf, len) ;
32873295 }
32883296 Vec :: from_raw_parts ( buf, len, cap)
0 commit comments