Commit a2b4d97
authored
Rollup merge of #79327 - TimDiekmann:static-alloc-pin-in-box, r=Mark-Simulacrum
Require allocator to be static for boxed `Pin`-API
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](https://www.reddit.com/r/rust/comments/jymzdw/the_story_continues_vec_now_supports_custom/gd7qak2?utm_source=share&utm_medium=web2x&context=3):
```rust
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.
```1 file changed
+25
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
330 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
331 | 334 | | |
332 | 335 | | |
333 | 336 | | |
| |||
802 | 805 | | |
803 | 806 | | |
804 | 807 | | |
805 | | - | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
806 | 812 | | |
807 | 813 | | |
808 | 814 | | |
| |||
1010 | 1016 | | |
1011 | 1017 | | |
1012 | 1018 | | |
1013 | | - | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1014 | 1023 | | |
1015 | 1024 | | |
1016 | 1025 | | |
| |||
1413 | 1422 | | |
1414 | 1423 | | |
1415 | 1424 | | |
1416 | | - | |
| 1425 | + | |
1417 | 1426 | | |
1418 | 1427 | | |
1419 | | - | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
1420 | 1432 | | |
1421 | 1433 | | |
1422 | 1434 | | |
| |||
1426 | 1438 | | |
1427 | 1439 | | |
1428 | 1440 | | |
1429 | | - | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1430 | 1445 | | |
1431 | 1446 | | |
1432 | 1447 | | |
| |||
1436 | 1451 | | |
1437 | 1452 | | |
1438 | 1453 | | |
1439 | | - | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
1440 | 1458 | | |
1441 | 1459 | | |
1442 | 1460 | | |
| |||
0 commit comments