@@ -428,7 +428,15 @@ impl<T: ?Sized> Box<T> {
428428 #[ stable( feature = "box_raw" , since = "1.4.0" ) ]
429429 #[ inline]
430430 pub fn into_raw ( b : Box < T > ) -> * mut T {
431- Box :: into_raw_non_null ( b) . as_ptr ( )
431+ let b = mem:: ManuallyDrop :: new ( b) ;
432+ let mut unique = b. 0 ;
433+ // Box is kind-of a library type, but recognized as a "unique pointer" by
434+ // Stacked Borrows. This function here corresponds to "reborrowing to
435+ // a raw pointer", but there is no actual reborrow here -- so
436+ // without some care, the pointer we are returning here still carries
437+ // the tag of `b`, with `Unique` permission.
438+ // We round-trip through a mutable reference to avoid that.
439+ unsafe { unique. as_mut ( ) as * mut T }
432440 }
433441
434442 /// Consumes the `Box`, returning the wrapped pointer as `NonNull<T>`.
@@ -451,6 +459,7 @@ impl<T: ?Sized> Box<T> {
451459 ///
452460 /// ```
453461 /// #![feature(box_into_raw_non_null)]
462+ /// #![allow(deprecated)]
454463 ///
455464 /// let x = Box::new(5);
456465 /// let ptr = Box::into_raw_non_null(x);
@@ -460,24 +469,24 @@ impl<T: ?Sized> Box<T> {
460469 /// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
461470 /// ```
462471 #[ unstable( feature = "box_into_raw_non_null" , issue = "47336" ) ]
472+ #[ rustc_deprecated(
473+ since = "1.44.0" ,
474+ reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead"
475+ ) ]
463476 #[ inline]
464477 pub fn into_raw_non_null ( b : Box < T > ) -> NonNull < T > {
465- Box :: into_unique ( b) . into ( )
478+ Box :: leak ( b) . into ( )
466479 }
467480
468- #[ unstable( feature = "ptr_internals" , issue = "none" , reason = "use into_raw_non_null instead" ) ]
481+ #[ unstable(
482+ feature = "ptr_internals" ,
483+ issue = "none" ,
484+ reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead"
485+ ) ]
469486 #[ inline]
470487 #[ doc( hidden) ]
471488 pub fn into_unique ( b : Box < T > ) -> Unique < T > {
472- let b = mem:: ManuallyDrop :: new ( b) ;
473- let mut unique = b. 0 ;
474- // Box is kind-of a library type, but recognized as a "unique pointer" by
475- // Stacked Borrows. This function here corresponds to "reborrowing to
476- // a raw pointer", but there is no actual reborrow here -- so
477- // without some care, the pointer we are returning here still carries
478- // the tag of `b`, with `Unique` permission.
479- // We round-trip through a mutable reference to avoid that.
480- unsafe { Unique :: new_unchecked ( unique. as_mut ( ) as * mut T ) }
489+ Box :: leak ( b) . into ( )
481490 }
482491
483492 /// Consumes and leaks the `Box`, returning a mutable reference,
0 commit comments