about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-27 17:26:37 -0700
committerbors <bors@rust-lang.org>2014-04-27 17:26:37 -0700
commitc2b6ab94e23886068a4bbb1679ce24771aa4b25a (patch)
tree11da12fb78bcc49b7aeb4aa2878830e355452317
parent8b24964012cffda83deb7749fdddd047a4144df4 (diff)
parent550c87e17dff0ff7f87a2b4c33fe25b16707e4f6 (diff)
downloadrust-c2b6ab94e23886068a4bbb1679ce24771aa4b25a.tar.gz
rust-c2b6ab94e23886068a4bbb1679ce24771aa4b25a.zip
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.
-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])] = &[