about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyan Mulligan <ryan@ryantm.com>2014-04-27 08:59:07 -0700
committerRyan Mulligan <ryan@ryantm.com>2014-04-27 10:37:02 -0700
commit550c87e17dff0ff7f87a2b4c33fe25b16707e4f6 (patch)
tree699550d2f2be6ee4409a2d2ed6aaea9c8a0659d4
parentb2a8fae84c290f6dbbff769de7f59f76a9400103 (diff)
downloadrust-550c87e17dff0ff7f87a2b4c33fe25b16707e4f6.tar.gz
rust-550c87e17dff0ff7f87a2b4c33fe25b16707e4f6.zip
add BigUint subtraction underflow error message
-rw-r--r--src/libnum/bigint.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs
index 77c94d01508..45cd7ee4701 100644
--- a/src/libnum/bigint.rs
+++ b/src/libnum/bigint.rs
@@ -230,7 +230,8 @@ impl Sub<BigUint, BigUint> for BigUint {
             lo
         }).collect();
 
-        assert_eq!(borrow, 0);     // <=> assert!((self >= other));
+        assert!(borrow == 0,
+                "Cannot subtract other from self because other is larger than self.");
         return BigUint::new(diff);
     }
 }
@@ -1755,6 +1756,13 @@ mod biguint_tests {
         }
     }
 
+    #[test]
+    #[should_fail]
+    fn test_sub_fail_on_underflow() {
+        let (a, b) : (BigUint, BigUint) = (Zero::zero(), One::one());
+        a - b;
+    }
+
     static mul_triples: &'static [(&'static [BigDigit],
                                    &'static [BigDigit],
                                    &'static [BigDigit])] = &[