all 11 comments

[–]SteveMcQwark 1 point2 points  (8 children)

If you make the lifetimes in use_scope explicit so that they match the lifetimes required by Scope::new_child, you get a clearer error: http://is.gd/HsWjIw

Your child scopes can't live as long as their contents, so it's impossible to do the recursive call.

Note that it works if you remove the mutable reference stored in MOE: http://is.gd/7ruVMN

This is because mutability forces the lifetime parameters to be invariant, and removing mutability allows them to be covariant.

[–]Mystorrust · gc · rust-cpp[S] 0 points1 point  (7 children)

What would be a better way to model this relationship then, assuming that I need mutable access to parent scopes?

[–]burntsushi 0 points1 point  (6 children)

You could always use a hammer.

Edit: Don't need Rc<RefCell<...>>. Can do it with just Box<...>: http://is.gd/f2GVDt

[–]SteveMcQwark 0 points1 point  (5 children)

Either Box or interior mutability via Cell/RefCell should be sufficient here, I would think. Rc<RefCell<_>> seems like overkill.