mirror of
https://github.com/enso-org/enso.git
synced 2024-12-25 16:53:10 +03:00
Reduce borrow scope (#6359)
Reduce the scope of a borrow, to prevent `BorrowError`s.
This commit is contained in:
parent
fe0c8fd9a3
commit
dd4dce2c3f
@ -805,7 +805,12 @@ impl LayerModel {
|
||||
|
||||
/// Clear the parent field and remove the layer from its parent's sublayer list.
|
||||
fn remove_from_parent(&self) {
|
||||
if let Some(parent) = self.parent.borrow_mut().take() {
|
||||
// Borrow `self.parent` only within the scope of this line. Note that if this expression
|
||||
// were used directly as the matched expression of the `if let`, the `RefMut` would not be
|
||||
// dropped until the end of the `if let` block, even though it is a temporary value within
|
||||
// the subexpression with `take`.
|
||||
let parent = self.parent.borrow_mut().take();
|
||||
if let Some(parent) = parent {
|
||||
parent.borrow_mut().remove(self.id());
|
||||
// Recompute depth order, in case removing a parent resolved a cycle.
|
||||
self.depth_order_dirty.set();
|
||||
|
Loading…
Reference in New Issue
Block a user