File tree 1 file changed +5
-7
lines changed
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> {
1019
1019
// the drain is complete and the Drain destructor is run.
1020
1020
self . head = drain_tail;
1021
1021
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
-
1027
1022
Drain {
1028
- deque,
1023
+ deque : NonNull :: from ( & mut * self ) ,
1029
1024
after_tail : drain_head,
1030
1025
after_head : head,
1031
1026
iter : Iter {
1032
1027
tail : drain_tail,
1033
1028
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 ( ) } ,
1035
1033
} ,
1036
1034
}
1037
1035
}
You can’t perform that action at this time.
0 commit comments