File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
src/librustc_mir/dataflow/move_paths Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,40 @@ impl<'tcx> MovePath<'tcx> {
7272
7373 parents
7474 }
75+
76+ /// Looks for the first child of `self` for which `f` returns `true`.
77+ ///
78+ /// `f` will **not** be called on `self`.
79+ pub fn find_child (
80+ & self ,
81+ move_paths : & IndexVec < MovePathIndex , MovePath < ' _ > > ,
82+ f : impl Fn ( MovePathIndex ) -> bool
83+ ) -> Option < MovePathIndex > {
84+ let mut todo = if let Some ( child) = self . first_child {
85+ vec ! [ child]
86+ } else {
87+ return None ;
88+ } ;
89+
90+ while let Some ( mpi) = todo. pop ( ) {
91+ if f ( mpi) {
92+ return Some ( mpi) ;
93+ }
94+
95+ let move_path = & move_paths[ mpi] ;
96+ if let Some ( child) = move_path. first_child {
97+ todo. push ( child) ;
98+ }
99+
100+ // After we've processed the original `mpi`, we should always
101+ // traverse the siblings of any of its children.
102+ if let Some ( sibling) = move_path. next_sibling {
103+ todo. push ( sibling) ;
104+ }
105+ }
106+
107+ None
108+ }
75109}
76110
77111impl < ' tcx > fmt:: Debug for MovePath < ' tcx > {
You can’t perform that action at this time.
0 commit comments