@@ -128,10 +128,10 @@ impl LocationState {
128
128
Ok ( transition)
129
129
}
130
130
131
- /// Like `perform_access`, but ignores the diagnostics, and also is pure.
132
- /// As such, it returns `Some(x)` if the transition succeeded, or `None`
133
- /// if there was an error.
134
- #[ allow ( unused ) ]
131
+ /// Like `perform_access`, but ignores the concrete error cause and also uses state-passing
132
+ /// rather than a mutable reference. As such, it returns `Some(x)` if the transition succeeded,
133
+ /// or `None` if there was an error.
134
+ #[ cfg ( test ) ]
135
135
fn perform_access_no_fluff (
136
136
mut self ,
137
137
access_kind : AccessKind ,
@@ -865,14 +865,18 @@ impl Tree {
865
865
live : & FxHashSet < BorTag > ,
866
866
) -> Option < UniIndex > {
867
867
let node = self . nodes . get ( idx) . unwrap ( ) ;
868
+
869
+ // We never want to replace the root node, as it is also kept in `root_ptr_tags`.
868
870
if node. children . len ( ) != 1 || live. contains ( & node. tag ) || node. parent . is_none ( ) {
869
871
return None ;
870
872
}
871
- // Since protected nodes are never GC'd (see `borrow_tracker::GlobalStateInner ::visit_provenance`),
873
+ // Since protected nodes are never GC'd (see `borrow_tracker::FrameExtra ::visit_provenance`),
872
874
// we know that `node` is not protected because otherwise `live` would
873
875
// have contained `node.tag`.
874
876
let child_idx = node. children [ 0 ] ;
875
877
let child = self . nodes . get ( child_idx) . unwrap ( ) ;
878
+ // Check that for that one child, `can_be_replaced_by_child` holds for the permission
879
+ // on all locations.
876
880
for ( _, data) in self . rperms . iter_all ( ) {
877
881
let parent_perm =
878
882
data. get ( idx) . map ( |x| x. permission ) . unwrap_or_else ( || node. default_initial_perm ) ;
@@ -893,7 +897,6 @@ impl Tree {
893
897
/// should have no children, but this is not checked, so that nodes
894
898
/// whose children were rotated somewhere else can be deleted without
895
899
/// having to first modify them to clear that array.
896
- /// otherwise (i.e. the GC should have marked it as removable).
897
900
fn remove_useless_node ( & mut self , this : UniIndex ) {
898
901
// Due to the API of UniMap we must make sure to call
899
902
// `UniValMap::remove` for the key of this node on *all* maps that used it
@@ -950,17 +953,18 @@ impl Tree {
950
953
// Remove all useless children.
951
954
children_of_node. retain_mut ( |idx| {
952
955
if self . is_useless ( * idx, live) {
953
- // delete it everywhere else
956
+ // Delete `idx` node everywhere else.
954
957
self . remove_useless_node ( * idx) ;
955
- // and delete it from children_of_node
958
+ // And delete it from children_of_node.
956
959
false
957
960
} else {
958
961
if let Some ( nextchild) = self . can_be_replaced_by_single_child ( * idx, live) {
959
- // delete the in-between child
962
+ // `nextchild` is our grandchild, and will become our direct child.
963
+ // Delete the in-between node, `idx`.
960
964
self . remove_useless_node ( * idx) ;
961
- // set the new child's parent
965
+ // Set the new child's parent.
962
966
self . nodes . get_mut ( nextchild) . unwrap ( ) . parent = Some ( * tag) ;
963
- // save the new child in children_of_node
967
+ // Save the new child in children_of_node.
964
968
* idx = nextchild;
965
969
}
966
970
// retain it
0 commit comments