diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-02-26 15:34:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-26 15:34:29 +0100 |
| commit | 86b9377dd67019db9f0dacb1c077eb6ff24a64ae (patch) | |
| tree | c08b61d06eddd53b0b095165494186d05bc1482f /src/libstd/sys/unix/stack_overflow.rs | |
| parent | 3a0d106109d73ed2e45a9925a9512ade2afb7df9 (diff) | |
| parent | 329022dfad7199053cbe225e8d7d13ebbd5eb230 (diff) | |
| download | rust-86b9377dd67019db9f0dacb1c077eb6ff24a64ae.tar.gz rust-86b9377dd67019db9f0dacb1c077eb6ff24a64ae.zip | |
Rollup merge of #68712 - HeroicKatora:finalize-ref-cell, r=dtolnay
Add methods to 'leak' RefCell borrows as references with the lifetime of the original reference
Usually, references to the interior are only created by the `Deref` and
`DerefMut` impl of the guards `Ref` and `RefMut`. Note that `RefCell`
already has to cope with leaks of such guards which, when it occurs,
effectively makes it impossible to ever acquire a mutable guard or any
guard for `Ref` and `RefMut` respectively. It is already safe to use
this to create a reference to the inner of the ref cell that lives as
long as the reference to the `RefCell` itself, e.g.
```rust
fn leak(r: &RefCell<usize>) -> Option<&usize> {
let guard = r.try_borrow().ok()?;
let leaked = Box::leak(Box::new(guard));
Some(&*leaked)
}
```
The newly added methods allow the same reference conversion without an
indirection over a leaked allocation. It's placed on the `Ref`/`RefMut` to
compose with both borrow and try_borrow directly.
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions
