Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box::pin_in violates pin's drop guarantee #226

Open
zetanumbers opened this issue Jan 18, 2024 · 1 comment · May be fixed by #228
Open

Box::pin_in violates pin's drop guarantee #226

zetanumbers opened this issue Jan 18, 2024 · 1 comment · May be fixed by #228

Comments

@zetanumbers
Copy link
Contributor

This is incorrect and violates pin's drop guarantee which in turn breaks existing correct code assuming this rule. For this reason std::box::Box::pin_in has A: 'static bound over the allocator generic type argument.

@zetanumbers
Copy link
Contributor Author

rust-lang/rust#79327 (comment)

Allocators has to retain their validity until the instance and all of its clones are dropped. When pinning a value, it must live forever, thus, the allocator requires a 'static lifetime for pinning a value. Example from reddit:

let alloc = MyAlloc(/* ... */);
let pinned = Box::pin_in(42, alloc);
mem::forget(pinned); // Now `value` must live forever
// Otherwise `Pin`'s invariants are violated, storage invalidated
// before Drop was called.
// borrow of `memory` can end here, there is no value keeping it.
drop(alloc); // Oh, value doesn't live forever.

@cynecx cynecx linked a pull request Feb 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant