Skip to content

Chaining Arc<RefCell<..>> confuses borrowck. #26706

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
dpc opened this issue Jul 1, 2015 · 6 comments
Closed

Chaining Arc<RefCell<..>> confuses borrowck. #26706

dpc opened this issue Jul 1, 2015 · 6 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@dpc
Copy link
Contributor

dpc commented Jul 1, 2015

http://is.gd/rNjThX

use std::sync::Arc;
use std::cell::RefCell;

struct A {
    a : Arc<RefCell<i32>>
}

struct B {
    b : Arc<RefCell<A>>
}

impl B {
    fn is_foo(&self) -> bool {
        *self.b.borrow().a.borrow() == 2
    }
}

This should compile, but it does not. Breaking the chain is a workaround.

@dpc dpc changed the title Chaining Arc<RefCell<..>> confused borrowck. Chaining Arc<RefCell<..>> confuses borrowck. Jul 1, 2015
@Aatch Aatch added the A-lifetimes Area: Lifetimes / regions label Jul 1, 2015
@Aatch
Copy link
Contributor

Aatch commented Jul 1, 2015

cc @pnkfelix is this an issue with destruction scopes specifically, or related to rvalue lifetimes in general?

@arielb1
Copy link
Contributor

arielb1 commented Jul 1, 2015

This is intentional well-known fallout of dropck - our current definition of strictly-outlives is not fine-grained enough.

@arielb1
Copy link
Contributor

arielb1 commented Jul 1, 2015

@Aatch

The issue here is that the first borrow must be drop-valid during the destruction of the second borrow, but the current destruction-scope implementation requires it to be drop-valid for the entire is_foo block.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 1, 2015

cc #22321

@pnkfelix
Copy link
Member

pnkfelix commented Jul 1, 2015

this seems like a probable dupe of #22323

@alexcrichton
Copy link
Member

Yeah I think this is just a dupe of #22323 as well.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

5 participants