Skip to content

Commit b5e1b00

Browse files
Add find_child method to MovePath
1 parent a12fe27 commit b5e1b00

File tree

1 file changed

+34
-0
lines changed
  • src/librustc_mir/dataflow/move_paths

1 file changed

+34
-0
lines changed

src/librustc_mir/dataflow/move_paths/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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

77111
impl<'tcx> fmt::Debug for MovePath<'tcx> {

0 commit comments

Comments
 (0)