]> git.lizzy.rs Git - rust.git/commitdiff
Cleanup Deref impls and add ?Sized bound to &mut T impls
authorTaylor Cramer <cramertj@google.com>
Tue, 18 Sep 2018 18:48:03 +0000 (11:48 -0700)
committerTaylor Cramer <cramertj@google.com>
Tue, 18 Sep 2018 22:42:51 +0000 (15:42 -0700)
src/libcore/pin.rs

index 3ab6dcd8531d138356d7abd82cbdc24f6d8c7749..d09a545aecfaf8a6072aedeada9e54f072d540c6 100644 (file)
@@ -154,7 +154,7 @@ pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
     pub fn as_ref(self: &Pin<P>) -> Pin<&P::Target> {
-        unsafe { Pin::new_unchecked(&**self) }
+        unsafe { Pin::new_unchecked(&*self.pointer) }
     }
 }
 
@@ -212,7 +212,7 @@ pub fn get_ref(this: Pin<&'a T>) -> &'a T {
     }
 }
 
-impl<'a, T> Pin<&'a mut T> {
+impl<'a, T: ?Sized> Pin<&'a mut T> {
     /// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
@@ -278,7 +278,7 @@ pub unsafe fn map_unchecked_mut<U, F>(this: Pin<&'a mut T>, func: F) -> Pin<&'a
 impl<P: Deref> Deref for Pin<P> {
     type Target = P::Target;
     fn deref(&self) -> &P::Target {
-        &*self.pointer
+        Pin::get_ref(Pin::as_ref(self))
     }
 }
 
@@ -288,7 +288,7 @@ impl<P: DerefMut> DerefMut for Pin<P>
     P::Target: Unpin
 {
     fn deref_mut(&mut self) -> &mut P::Target {
-        &mut *self.pointer
+        Pin::get_mut(Pin::as_mut(self))
     }
 }