Skip to content

Commit 7387f48

Browse files
committed
Require allocator to be static for boxed Pin-API
1 parent a1a13b2 commit 7387f48

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

library/alloc/src/boxed.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ impl<T, A: AllocRef> Box<T, A> {
327327
/// `x` will be pinned in memory and unable to be moved.
328328
#[unstable(feature = "allocator_api", issue = "32838")]
329329
#[inline(always)]
330-
pub fn pin_in(x: T, alloc: A) -> Pin<Self> {
330+
pub fn pin_in(x: T, alloc: A) -> Pin<Self>
331+
where
332+
A: 'static,
333+
{
331334
Self::new_in(x, alloc).into()
332335
}
333336

@@ -802,7 +805,10 @@ impl<T: ?Sized, A: AllocRef> Box<T, A> {
802805
///
803806
/// This is also available via [`From`].
804807
#[unstable(feature = "box_into_pin", issue = "62370")]
805-
pub fn into_pin(boxed: Self) -> Pin<Self> {
808+
pub fn into_pin(boxed: Self) -> Pin<Self>
809+
where
810+
A: 'static,
811+
{
806812
// It's not possible to move or replace the insides of a `Pin<Box<T>>`
807813
// when `T: !Unpin`, so it's safe to pin it directly without any
808814
// additional requirements.
@@ -1010,7 +1016,10 @@ impl<T> From<T> for Box<T> {
10101016
}
10111017

10121018
#[stable(feature = "pin", since = "1.33.0")]
1013-
impl<T: ?Sized, A: AllocRef> From<Box<T, A>> for Pin<Box<T, A>> {
1019+
impl<T: ?Sized, A: AllocRef> From<Box<T, A>> for Pin<Box<T, A>>
1020+
where
1021+
A: 'static,
1022+
{
10141023
/// Converts a `Box<T>` into a `Pin<Box<T>>`
10151024
///
10161025
/// This conversion does not allocate on the heap and happens in place.
@@ -1413,10 +1422,13 @@ impl<T: ?Sized, A: AllocRef> AsMut<T> for Box<T, A> {
14131422
* could have a method to project a Pin<T> from it.
14141423
*/
14151424
#[stable(feature = "pin", since = "1.33.0")]
1416-
impl<T: ?Sized, A: AllocRef> Unpin for Box<T, A> {}
1425+
impl<T: ?Sized, A: AllocRef> Unpin for Box<T, A> where A: 'static {}
14171426

14181427
#[unstable(feature = "generator_trait", issue = "43122")]
1419-
impl<G: ?Sized + Generator<R> + Unpin, R, A: AllocRef> Generator<R> for Box<G, A> {
1428+
impl<G: ?Sized + Generator<R> + Unpin, R, A: AllocRef> Generator<R> for Box<G, A>
1429+
where
1430+
A: 'static,
1431+
{
14201432
type Yield = G::Yield;
14211433
type Return = G::Return;
14221434

@@ -1426,7 +1438,10 @@ impl<G: ?Sized + Generator<R> + Unpin, R, A: AllocRef> Generator<R> for Box<G, A
14261438
}
14271439

14281440
#[unstable(feature = "generator_trait", issue = "43122")]
1429-
impl<G: ?Sized + Generator<R>, R, A: AllocRef> Generator<R> for Pin<Box<G, A>> {
1441+
impl<G: ?Sized + Generator<R>, R, A: AllocRef> Generator<R> for Pin<Box<G, A>>
1442+
where
1443+
A: 'static,
1444+
{
14301445
type Yield = G::Yield;
14311446
type Return = G::Return;
14321447

@@ -1436,7 +1451,10 @@ impl<G: ?Sized + Generator<R>, R, A: AllocRef> Generator<R> for Pin<Box<G, A>> {
14361451
}
14371452

14381453
#[stable(feature = "futures_api", since = "1.36.0")]
1439-
impl<F: ?Sized + Future + Unpin, A: AllocRef> Future for Box<F, A> {
1454+
impl<F: ?Sized + Future + Unpin, A: AllocRef> Future for Box<F, A>
1455+
where
1456+
A: 'static,
1457+
{
14401458
type Output = F::Output;
14411459

14421460
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

0 commit comments

Comments
 (0)