@@ -1472,18 +1472,16 @@ impl<L: Language> Explain<L> {
14721472 ) ;
14731473
14741474 // calculate distance to find upper bound
1475- b. checked_add ( c)
1476- . unwrap_or_else ( || panic ! ( "overflow in proof size calculation!" ) )
1477- . checked_sub (
1478- a. checked_mul ( 2 )
1479- . unwrap_or_else ( || panic ! ( "overflow in proof size calculation!" ) ) ,
1480- )
1481- . unwrap_or_else ( || panic ! ( "common ancestor distance was too large!" ) )
1475+ match b. checked_add ( c) {
1476+ Some ( added) => added
1477+ . checked_sub ( a. checked_mul ( 2 ) . unwrap_or ( 0 ) )
1478+ . unwrap_or ( usize:: MAX ) ,
1479+ None => usize:: MAX ,
1480+ }
14821481
14831482 //assert_eq!(dist+1, Explanation::new(self.explain_enodes(left, right, &mut Default::default())).make_flat_explanation().len());
14841483 }
14851484
1486- // TODO use bigint, this overflows easily
14871485 fn congruence_distance (
14881486 & mut self ,
14891487 current : Id ,
@@ -1498,9 +1496,11 @@ impl<L: Language> Explain<L> {
14981496 . iter ( )
14991497 . zip ( next_node. children ( ) . iter ( ) )
15001498 {
1501- cost = cost
1502- . checked_add ( self . distance_between ( * left_child, * right_child, distance_memo) )
1503- . unwrap ( ) ;
1499+ cost = cost. saturating_add ( self . distance_between (
1500+ * left_child,
1501+ * right_child,
1502+ distance_memo,
1503+ ) ) ;
15041504 }
15051505 cost
15061506 }
@@ -1673,7 +1673,7 @@ impl<L: Language> Explain<L> {
16731673
16741674 for neighbor in & self . explainfind [ usize:: from ( current) ] . neighbors {
16751675 if let Justification :: Rule ( _) = neighbor. justification {
1676- let neighbor_cost = cost_so_far. checked_add ( 1 ) . unwrap ( ) ;
1676+ let neighbor_cost = cost_so_far. saturating_add ( 1 ) ;
16771677 todo. push ( HeapState {
16781678 item : neighbor. clone ( ) ,
16791679 cost : neighbor_cost,
0 commit comments