Skip to content

Commit 572c390

Browse files
committed
Stabilize box_into_pin
1 parent b5a2d27 commit 572c390

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

library/alloc/src/boxed.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,33 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11751175
/// This conversion does not allocate on the heap and happens in place.
11761176
///
11771177
/// This is also available via [`From`].
1178-
#[unstable(feature = "box_into_pin", issue = "62370")]
1178+
///
1179+
/// # Notes
1180+
///
1181+
/// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`,
1182+
/// as it'll introduce an ambiguity when calling `Pin::from`.
1183+
/// A demonstration of such a poor impl is shown below.
1184+
///
1185+
/// ```compile_fail
1186+
/// # use std::pin::Pin;
1187+
/// struct Foo; // A type defined in this crate.
1188+
/// impl From<Box<()>> for Pin<Foo> {
1189+
/// fn from(_: Box<()>) -> Pin<Foo> {
1190+
/// Pin::new(Foo)
1191+
/// }
1192+
/// }
1193+
///
1194+
/// let foo = Box::new(());
1195+
/// let bar = Pin::from(foo);
1196+
/// ```
1197+
#[stable(feature = "box_into_pin", since = "1.63.0")]
11791198
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11801199
pub const fn into_pin(boxed: Self) -> Pin<Self>
11811200
where
11821201
A: 'static,
11831202
{
11841203
// It's not possible to move or replace the insides of a `Pin<Box<T>>`
1185-
// when `T: !Unpin`, so it's safe to pin it directly without any
1204+
// when `T: !Unpin`, so it's safe to pin it directly without any
11861205
// additional requirements.
11871206
unsafe { Pin::new_unchecked(boxed) }
11881207
}

0 commit comments

Comments
 (0)