From 0247119676fb58c50e156ef5984aae304414da2c Mon Sep 17 00:00:00 2001 From: cactter Date: Fri, 22 Jul 2022 08:05:43 +0800 Subject: [PATCH] Shrink unsafe block --- src/collections/deque/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/collections/deque/mod.rs b/src/collections/deque/mod.rs index f915dff5..d43068b7 100644 --- a/src/collections/deque/mod.rs +++ b/src/collections/deque/mod.rs @@ -242,9 +242,9 @@ impl Deque { // The content of ring buffer won't overlapped, so it's safe to // call `copy_nonoverlapping`. It's also safe to advance the // pointer by `old_cap` since the buffer has been doubled. + let src = self.ptr(); // 4-1 + let dst = unsafe { self.ptr().add(old_cap) }; // 4-2 unsafe { - let src = self.ptr(); // 4-1 - let dst = self.ptr().add(old_cap); // 4-2 ptr::copy_nonoverlapping(src, dst, self.head); } self.head += old_cap; // 5 @@ -354,11 +354,11 @@ impl<'a, T> Iterator for IterMut<'a, T> { // trait: the `&mut self` is bound to an anonymous lifetime which rustc // cannot figure out whether it would outlive returning element. Hence // the explicit pointer casting is required. - unsafe { + let ptr = self.ring_buf as *mut [T]; // 1 - let slice = &mut *ptr; // 2 + let slice = unsafe { &mut *ptr }; // 2 slice.get_mut(tail) // 3 - } + } } // ANCHOR_END: IterMut