@@ -1009,7 +1009,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
10091009 /// ```
10101010 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10111011 pub fn iter ( & self ) -> Iter < ' _ , T > {
1012- Iter { tail : self . tail , head : self . head , ring : unsafe { self . buffer_as_slice ( ) } }
1012+ Iter :: new ( unsafe { self . buffer_as_slice ( ) } , self . tail , self . head )
10131013 }
10141014
10151015 /// Returns a front-to-back iterator that returns mutable references.
@@ -1188,12 +1188,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
11881188 R : RangeBounds < usize > ,
11891189 {
11901190 let ( tail, head) = self . range_tail_head ( range) ;
1191- Iter {
1192- tail,
1193- head,
1194- // The shared reference we have in &self is maintained in the '_ of Iter.
1195- ring : unsafe { self . buffer_as_slice ( ) } ,
1196- }
1191+ // The shared reference we have in &self is maintained in the '_ of Iter.
1192+ Iter :: new ( unsafe { self . buffer_as_slice ( ) } , tail, head)
11971193 }
11981194
11991195 /// Creates an iterator that covers the specified mutable range in the deque.
@@ -1309,16 +1305,15 @@ impl<T, A: Allocator> VecDeque<T, A> {
13091305 self . head = drain_tail;
13101306
13111307 let deque = NonNull :: from ( & mut * self ) ;
1312- let iter = Iter {
1313- tail : drain_tail,
1314- head : drain_head,
1308+ unsafe {
13151309 // Crucially, we only create shared references from `self` here and read from
13161310 // it. We do not write to `self` nor reborrow to a mutable reference.
13171311 // Hence the raw pointer we created above, for `deque`, remains valid.
1318- ring : unsafe { self . buffer_as_slice ( ) } ,
1319- } ;
1312+ let ring = self . buffer_as_slice ( ) ;
1313+ let iter = Iter :: new ( ring , drain_tail , drain_head ) ;
13201314
1321- unsafe { Drain :: new ( drain_head, head, iter, deque) }
1315+ Drain :: new ( drain_head, head, iter, deque)
1316+ }
13221317 }
13231318
13241319 /// Clears the deque, removing all values.
0 commit comments