Skip to content

NLL / MIR-borrowck regression in atomic_refcell crate #48178

Closed
@SimonSapin

Description

@SimonSapin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions