@@ -735,20 +735,31 @@ impl Map {
735735 }
736736
737737 /// Locates the given place, if it exists in the tree.
738- pub fn find ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
738+ pub fn find_extra (
739+ & self ,
740+ place : PlaceRef < ' _ > ,
741+ extra : impl IntoIterator < Item = TrackElem > ,
742+ ) -> Option < PlaceIndex > {
739743 let mut index = * self . locals . get ( place. local ) ?. as_ref ( ) ?;
740744
741745 for & elem in place. projection {
742746 index = self . apply ( index, elem. try_into ( ) . ok ( ) ?) ?;
743747 }
748+ for elem in extra {
749+ index = self . apply ( index, elem) ?;
750+ }
744751
745752 Some ( index)
746753 }
747754
748755 /// Locates the given place, if it exists in the tree.
756+ pub fn find ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
757+ self . find_extra ( place, [ ] )
758+ }
759+
760+ /// Locates the given place and applies `Discriminant`, if it exists in the tree.
749761 pub fn find_discr ( & self , place : PlaceRef < ' _ > ) -> Option < PlaceIndex > {
750- let index = self . find ( place) ?;
751- self . apply ( index, TrackElem :: Discriminant )
762+ self . find_extra ( place, [ TrackElem :: Discriminant ] )
752763 }
753764
754765 /// Iterate over all direct children.
@@ -763,14 +774,14 @@ impl Map {
763774 ///
764775 /// `tail_elem` allows to support discriminants that are not a place in MIR, but that we track
765776 /// as such.
766- fn for_each_aliasing_place (
777+ pub fn for_each_aliasing_place (
767778 & self ,
768779 place : PlaceRef < ' _ > ,
769780 tail_elem : Option < TrackElem > ,
770781 f : & mut impl FnMut ( PlaceIndex ) ,
771782 ) {
772783 let Some ( & Some ( mut index) ) = self . locals . get ( place. local ) else {
773- // The local is not tracked at all, nothing to invalidate .
784+ // The local is not tracked at all, so it does not alias anything .
774785 return ;
775786 } ;
776787 let elems = place
@@ -782,7 +793,7 @@ impl Map {
782793 let Ok ( elem) = elem else { return } ;
783794 let sub = self . apply ( index, elem) ;
784795 if let TrackElem :: Variant ( ..) | TrackElem :: Discriminant = elem {
785- // Writing to an enum variant field invalidates the other variants and the discriminant .
796+ // Enum variant fields and enum discriminants alias each another .
786797 self . for_each_variant_sibling ( index, sub, f) ;
787798 }
788799 if let Some ( sub) = sub {
@@ -795,7 +806,7 @@ impl Map {
795806 }
796807
797808 /// Invoke the given function on all the descendants of the given place, except one branch.
798- pub fn for_each_variant_sibling (
809+ fn for_each_variant_sibling (
799810 & self ,
800811 parent : PlaceIndex ,
801812 preserved_child : Option < PlaceIndex > ,
0 commit comments