about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
diff options
context:
space:
mode:
authorAndreas Molzer <andreas.molzer@gmx.de>2020-01-29 21:26:16 +0100
committerAndreas Molzer <andreas.molzer@gmx.de>2020-01-31 21:08:49 +0100
commit14999dd74b38ca79b80772f4f33425574faff89a (patch)
tree501f6d6090bd19ebe00109e7d3ed5d27d3c73160 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
parent698fcd38fa9548e64a2092ff48c9d15ceb57d40c (diff)
downloadrust-14999dd74b38ca79b80772f4f33425574faff89a.tar.gz
rust-14999dd74b38ca79b80772f4f33425574faff89a.zip
Add methods to leak RefCell borrows to references
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 and composing with both borrow and
try_borrow without additional method combinations.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs')
0 files changed, 0 insertions, 0 deletions