Skip to content

NLL / MIR-borrowck regression in atomic_refcell crate #48178

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

Closed
SimonSapin opened this issue Feb 13, 2018 · 4 comments
Closed

NLL / MIR-borrowck regression in atomic_refcell crate #48178

SimonSapin opened this issue Feb 13, 2018 · 4 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.

Comments

@SimonSapin
Copy link
Contributor

On nightly-2018-02-12 b8398d9, https://github.com/bholley/atomic_refcell builds with or without RUSTFLAGS=-Znll or RUSTFLAGS=-Zborrowck=mir.

On nightly-2018-02-13 16362c7, either flag causes the error below.

Commit range: b8398d9...16362c7

error[E0597]: `*orig.value` does not live long enough
   --> src/lib.rs:309:22
    |
309 |             value: f(orig.value),
    |                      ^^^^^^^^^^ borrowed value does not live long enough
...
312 |     }
    |     - borrowed value only lives until here
    |
    = note: borrowed value must be valid for lifetime '_#3r...

Reduced test case:

pub struct AtomicRefMut<'b, T: ?Sized + 'b> {
    value: &'b mut T,
    borrow: AtomicBorrowRefMut<'b>,
}

struct AtomicBorrowRefMut<'b> {
    borrow: &'b (),
}

impl<'b> Drop for AtomicBorrowRefMut<'b> {
    fn drop(&mut self) {}
}

impl<'b, T: ?Sized> AtomicRefMut<'b, T> {
    pub fn map<U: ?Sized, F>(orig: AtomicRefMut<'b, T>, f: F) -> AtomicRefMut<'b, U>
        where F: FnOnce(&mut T) -> &mut U
    {
        AtomicRefMut {
            value: f(orig.value),
            borrow: orig.borrow,
        }
    }
}

CC @nikomatsakis

@pietroalbini pietroalbini added A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. WG-compiler-nll labels Feb 13, 2018
@sapphire-arches sapphire-arches added this to the NLL: Valid code works milestone Feb 13, 2018
@nikomatsakis
Copy link
Contributor

I believe that this will be addressed by #47917

@nikomatsakis
Copy link
Contributor

cc @davidtwco -- can you quickly test?

@davidtwco
Copy link
Member

@nikomatsakis seems to be working fine on #47917.

@nikomatsakis
Copy link
Contributor

Working now:

https://play.rust-lang.org/?gist=189add0e963a75cb406c5fadc3e0190e&version=nightly

Closing since I think that the tests from #47917 suffice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants