diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index a8bf47c..be1241c 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -442,22 +442,15 @@ impl FutureMoves { self.arena = moves .into_iter() .map(|mut node| { - if let Some(parent) = node.parent.as_mut() { - if let Some(new_parent) = index_map[*parent] { - *parent = new_parent; - } else { - // make sure we don't have dangling parents - node.parent = None; - } - } + node.parent = node + .parent + .and_then(|parent| index_map.get(parent).and_then(|&x| x)); for c in node.children.as_mut_slice() { - debug_assert_ne!( - index_map.get(*c).and_then(|&x| x), - None, - "index_map should contain the child's index" - ); - *c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() }; + *c = index_map + .get(*c) + .and_then(|&x| x) + .expect("index_map should contain the child's index"); } node