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

Add methods to 'leak' RefCell borrows as references with the lifetime of the original reference #68712

Merged
merged 3 commits into from
Feb 26, 2020

Commits on Jan 31, 2020

  1. 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.
    HeroicKatora committed Jan 31, 2020
    Configuration menu
    Copy the full SHA
    14999dd View commit details
    Browse the repository at this point in the history

Commits on Feb 12, 2020

  1. Configuration menu
    Copy the full SHA
    99b4357 View commit details
    Browse the repository at this point in the history

Commits on Feb 24, 2020

  1. Address method comments

    HeroicKatora committed Feb 24, 2020
    Configuration menu
    Copy the full SHA
    329022d View commit details
    Browse the repository at this point in the history