Motivation behind `Box::pin_in` requiring `A: 'static`

So there's Box::pin_in function under allocator_api feature. This function has where clause A: 'static where A is allocator type. Making it impossible to use with allocator that is bound to non-'static lifetime.

I can't see any reason for this where clause. Can anyone explain me the motivation behind it?
As I understand, Pin<Box<T, A>> won't allow moving T out unless T is Unpin and will drop the T before A expires. So even if A expires at some point it won't allow violation of Pin, right?

I don't think this has anything to do with Pin. Does the other _in methods not also require static?

No, other methods do not require A: 'static.
I was pointed out on the PR that added the bound.
Turned out the problem is that it is safe to skip Dropping of the boxed value. mem::forget and Box::leak can do that.
And memory will become invalid without Drop glue which is incorrect for Pinned value.

The PR, for reference:

https://github.com/rust-lang/rust/pull/79327

Ah right this makes sense. The reason it's normally safe to forget a pinned box is that it leaks the memory, but here you can actually reclaim it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.