File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -1019,19 +1019,17 @@ impl<T> VecDeque<T> {
10191019 // the drain is complete and the Drain destructor is run.
10201020 self . head = drain_tail;
10211021
1022- // `deque` and `ring` overlap in what they point to, so we must make sure
1023- // that `ring` is "derived-from" `deque`, or else even just creating ring
1024- // from `self` already invalidates `deque`.
1025- let deque = NonNull :: from ( & mut * self ) ;
1026-
10271022 Drain {
1028- deque,
1023+ deque : NonNull :: from ( & mut * self ) ,
10291024 after_tail : drain_head,
10301025 after_head : head,
10311026 iter : Iter {
10321027 tail : drain_tail,
10331028 head : drain_head,
1034- ring : unsafe { ( & mut * deque. as_ptr ( ) ) . buffer_as_mut_slice ( ) } ,
1029+ // Crucially, we only create shared references from `self` here and read from
1030+ // it. We do not write to `self` nor reborrow to a mutable reference.
1031+ // Hence the raw pointer we created above, for `deque`, remains valid.
1032+ ring : unsafe { self . buffer_as_slice ( ) } ,
10351033 } ,
10361034 }
10371035 }
You can’t perform that action at this time.
0 commit comments