about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-22 18:43:07 +0530
committerGitHub <noreply@github.com>2020-02-22 18:43:07 +0530
commit4f71270d7b6910ddd123432da5ace0c167006c27 (patch)
treea06f4d710ab707d02dda46c37eb70ba81f3bccc5 /src
parent541b407c140bd8848fdeeba3448bc94ed72fd6a7 (diff)
parente1c8c8cf63b48c798c1954749e58e99c6cc50093 (diff)
downloadrust-4f71270d7b6910ddd123432da5ace0c167006c27.tar.gz
rust-4f71270d7b6910ddd123432da5ace0c167006c27.zip
Rollup merge of #69354 - MichaelMcDonnell:duration_overflow_test, r=Centril
Test `Duration::new` panics on overflow

A `Duration` is created from a second and nanoseconds variable. The
documentation says: "This constructor will panic if the carry from the
nanoseconds overflows the seconds counter". This was, however, not tested
in the tests. I doubt the behavior will ever regress, but it is usually a
good idea to test all documented behavior.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/tests/time.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs
index 273f1258bb0..c1fbdf7df76 100644
--- a/src/libcore/tests/time.rs
+++ b/src/libcore/tests/time.rs
@@ -12,6 +12,12 @@ fn creation() {
 }
 
 #[test]
+#[should_panic]
+fn new_overflow() {
+    let _ = Duration::new(::core::u64::MAX, 1_000_000_000);
+}
+
+#[test]
 fn secs() {
     assert_eq!(Duration::new(0, 0).as_secs(), 0);
     assert_eq!(Duration::new(0, 500_000_005).as_secs(), 0);