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