diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-06-02 11:13:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-02 11:13:23 +0200 |
| commit | 9225f78b7403f3bc0a7fa10f24e7af415b33bea7 (patch) | |
| tree | 89d4a93ea71320aed93f40f087495ba375a2b2c5 | |
| parent | 5c041f98fa121a5e8ae61f755ac3776565a7a595 (diff) | |
| parent | 572c39000ba24a254637f8e53bb5933fbd5ebef7 (diff) | |
| download | rust-9225f78b7403f3bc0a7fa10f24e7af415b33bea7.tar.gz rust-9225f78b7403f3bc0a7fa10f24e7af415b33bea7.zip | |
Rollup merge of #97397 - JohnTitor:stabilize-box-into-pin, r=Mark-Simulacrum
Stabilize `box_into_pin` FCP has been completed: https://github.com/rust-lang/rust/issues/62370#issuecomment-1012162279 Also, adds notes as per https://github.com/rust-lang/rust/issues/62370#issuecomment-1004108116 Closes #62370
| -rw-r--r-- | library/alloc/src/boxed.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 41f3b1fa3dd..e2c692b5299 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1175,14 +1175,33 @@ impl<T: ?Sized, A: Allocator> Box<T, A> { /// This conversion does not allocate on the heap and happens in place. /// /// This is also available via [`From`]. - #[unstable(feature = "box_into_pin", issue = "62370")] + /// + /// # Notes + /// + /// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`, + /// as it'll introduce an ambiguity when calling `Pin::from`. + /// A demonstration of such a poor impl is shown below. + /// + /// ```compile_fail + /// # use std::pin::Pin; + /// struct Foo; // A type defined in this crate. + /// impl From<Box<()>> for Pin<Foo> { + /// fn from(_: Box<()>) -> Pin<Foo> { + /// Pin::new(Foo) + /// } + /// } + /// + /// let foo = Box::new(()); + /// let bar = Pin::from(foo); + /// ``` + #[stable(feature = "box_into_pin", since = "1.63.0")] #[rustc_const_unstable(feature = "const_box", issue = "92521")] pub const fn into_pin(boxed: Self) -> Pin<Self> where A: 'static, { // It's not possible to move or replace the insides of a `Pin<Box<T>>` - // when `T: !Unpin`, so it's safe to pin it directly without any + // when `T: !Unpin`, so it's safe to pin it directly without any // additional requirements. unsafe { Pin::new_unchecked(boxed) } } |
