@@ -128,10 +128,10 @@ impl LocationState {
128128 Ok ( transition)
129129 }
130130
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 ) ]
135135 fn perform_access_no_fluff (
136136 mut self ,
137137 access_kind : AccessKind ,
@@ -865,14 +865,18 @@ impl Tree {
865865 live : & FxHashSet < BorTag > ,
866866 ) -> Option < UniIndex > {
867867 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`.
868870 if node. children . len ( ) != 1 || live. contains ( & node. tag ) || node. parent . is_none ( ) {
869871 return None ;
870872 }
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`),
872874 // we know that `node` is not protected because otherwise `live` would
873875 // have contained `node.tag`.
874876 let child_idx = node. children [ 0 ] ;
875877 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.
876880 for ( _, data) in self . rperms . iter_all ( ) {
877881 let parent_perm =
878882 data. get ( idx) . map ( |x| x. permission ) . unwrap_or_else ( || node. default_initial_perm ) ;
@@ -893,7 +897,6 @@ impl Tree {
893897 /// should have no children, but this is not checked, so that nodes
894898 /// whose children were rotated somewhere else can be deleted without
895899 /// having to first modify them to clear that array.
896- /// otherwise (i.e. the GC should have marked it as removable).
897900 fn remove_useless_node ( & mut self , this : UniIndex ) {
898901 // Due to the API of UniMap we must make sure to call
899902 // `UniValMap::remove` for the key of this node on *all* maps that used it
@@ -950,17 +953,18 @@ impl Tree {
950953 // Remove all useless children.
951954 children_of_node. retain_mut ( |idx| {
952955 if self . is_useless ( * idx, live) {
953- // delete it everywhere else
956+ // Delete `idx` node everywhere else.
954957 self . remove_useless_node ( * idx) ;
955- // and delete it from children_of_node
958+ // And delete it from children_of_node.
956959 false
957960 } else {
958961 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`.
960964 self . remove_useless_node ( * idx) ;
961- // set the new child's parent
965+ // Set the new child's parent.
962966 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.
964968 * idx = nextchild;
965969 }
966970 // retain it
0 commit comments