]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/boxed.rs
Rollup merge of #58183 - jethrogb:jb/alloc-box-guarantees, r=SimonSapin
[rust.git] / src / liballoc / boxed.rs
index 462f65ed794554a05bf3bbef0af1f5eaf0d5b962..e99ae6315f830c605c0f76d6f6809bc80f865e27 100644 (file)
@@ -81,7 +81,7 @@
     CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState
 };
 use core::ptr::{self, NonNull, Unique};
-use core::task::{LocalWaker, Poll};
+use core::task::{Waker, Poll};
 
 use crate::vec::Vec;
 use crate::raw_vec::RawVec;
@@ -212,10 +212,15 @@ pub fn into_raw_non_null(b: Box<T>) -> NonNull<T> {
     #[unstable(feature = "ptr_internals", issue = "0", reason = "use into_raw_non_null instead")]
     #[inline]
     #[doc(hidden)]
-    pub fn into_unique(b: Box<T>) -> Unique<T> {
-        let unique = b.0;
+    pub fn into_unique(mut b: Box<T>) -> Unique<T> {
+        // Box is kind-of a library type, but recognized as a "unique pointer" by
+        // Stacked Borrows.  This function here corresponds to "reborrowing to
+        // a raw pointer", but there is no actual reborrow here -- so
+        // without some care, the pointer we are returning here still carries
+        // the `Uniq` tag.  We round-trip through a mutable reference to avoid that.
+        let unique = unsafe { b.0.as_mut() as *mut T };
         mem::forget(b);
-        unique
+        unsafe { Unique::new_unchecked(unique) }
     }
 
     /// Consumes and leaks the `Box`, returning a mutable reference,
@@ -906,7 +911,7 @@ fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return>
 impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     type Output = F::Output;
 
-    fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
-        F::poll(Pin::new(&mut *self), lw)
+    fn poll(mut self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
+        F::poll(Pin::new(&mut *self), waker)
     }
 }