Skip to content

Commit 74564d7

Browse files
committed
Add A: 'static to Rc::pin_in and Arc::(try_)pin_in
This is required for soundness since `Pin` requires the memory to be leaked if the `Pin` is leaked.
1 parent 4f2bf73 commit 74564d7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

library/alloc/src/rc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,10 @@ impl<T, A: Allocator> Rc<T, A> {
883883
#[cfg(not(no_global_oom_handling))]
884884
#[unstable(feature = "allocator_api", issue = "32838")]
885885
#[inline]
886-
pub fn pin_in(value: T, alloc: A) -> Pin<Self> {
886+
pub fn pin_in(value: T, alloc: A) -> Pin<Self>
887+
where
888+
A: 'static,
889+
{
887890
unsafe { Pin::new_unchecked(Rc::new_in(value, alloc)) }
888891
}
889892

library/alloc/src/sync.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,21 @@ impl<T, A: Allocator> Arc<T, A> {
801801
#[cfg(not(no_global_oom_handling))]
802802
#[unstable(feature = "allocator_api", issue = "32838")]
803803
#[inline]
804-
pub fn pin_in(data: T, alloc: A) -> Pin<Arc<T, A>> {
804+
pub fn pin_in(data: T, alloc: A) -> Pin<Arc<T, A>>
805+
where
806+
A: 'static,
807+
{
805808
unsafe { Pin::new_unchecked(Arc::new_in(data, alloc)) }
806809
}
807810

808811
/// Constructs a new `Pin<Arc<T, A>>` in the provided allocator, return an error if allocation
809812
/// fails.
810813
#[inline]
811814
#[unstable(feature = "allocator_api", issue = "32838")]
812-
pub fn try_pin_in(data: T, alloc: A) -> Result<Pin<Arc<T, A>>, AllocError> {
815+
pub fn try_pin_in(data: T, alloc: A) -> Result<Pin<Arc<T, A>>, AllocError>
816+
where
817+
A: 'static,
818+
{
813819
unsafe { Ok(Pin::new_unchecked(Arc::try_new_in(data, alloc)?)) }
814820
}
815821

0 commit comments

Comments
 (0)