Skip to content

Commit c2b6ab9

Browse files
committed
auto merge of #13801 : ryantm/rust/master, r=alexcrichton
The previous error message using assert_eq! was quite cryptic. This should be more clear. I also added a test for the underflow case.
2 parents 8b24964 + 550c87e commit c2b6ab9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libnum/bigint.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ impl Sub<BigUint, BigUint> for BigUint {
230230
lo
231231
}).collect();
232232

233-
assert_eq!(borrow, 0); // <=> assert!((self >= other));
233+
assert!(borrow == 0,
234+
"Cannot subtract other from self because other is larger than self.");
234235
return BigUint::new(diff);
235236
}
236237
}
@@ -1755,6 +1756,13 @@ mod biguint_tests {
17551756
}
17561757
}
17571758

1759+
#[test]
1760+
#[should_fail]
1761+
fn test_sub_fail_on_underflow() {
1762+
let (a, b) : (BigUint, BigUint) = (Zero::zero(), One::one());
1763+
a - b;
1764+
}
1765+
17581766
static mul_triples: &'static [(&'static [BigDigit],
17591767
&'static [BigDigit],
17601768
&'static [BigDigit])] = &[

0 commit comments

Comments
 (0)