about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthew Piziak <matthew.piziak@gmail.com>2016-09-09 12:21:01 -0400
committerMatthew Piziak <matthew.piziak@gmail.com>2016-09-09 12:21:01 -0400
commitf6c4fcf12850602588d3c2dacffbf4b01308cb04 (patch)
treeaeceebca8f0acbd6c95a60e47151986b70c6ab44 /src
parentf1f40f850e2546c2c187514e3d61d17544ba433f (diff)
downloadrust-f6c4fcf12850602588d3c2dacffbf4b01308cb04.tar.gz
rust-f6c4fcf12850602588d3c2dacffbf4b01308cb04.zip
fix silent overflows on `Step` impls
r? @eddyb
Diffstat (limited to 'src')
-rw-r--r--src/libcore/iter/range.rs6
-rw-r--r--src/libcoretest/iter.rs14
2 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs
index 66d05d81d80..a9487b7f46d 100644
--- a/src/libcore/iter/range.rs
+++ b/src/libcore/iter/range.rs
@@ -95,11 +95,13 @@ macro_rules! step_impl_unsigned {
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn add_one(&self) -> Self {
                 *self + 1
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn sub_one(&self) -> Self {
                 *self - 1
             }
@@ -166,11 +168,13 @@ macro_rules! step_impl_signed {
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn add_one(&self) -> Self {
                 *self + 1
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn sub_one(&self) -> Self {
                 *self - 1
             }
@@ -215,11 +219,13 @@ macro_rules! step_impl_no_between {
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn add_one(&self) -> Self {
                 *self + 1
             }
 
             #[inline]
+            #[rustc_inherit_overflow_checks]
             fn sub_one(&self) -> Self {
                 *self - 1
             }
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index 27eb25537f3..7671ef2e8b9 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -916,6 +916,20 @@ fn test_range_step() {
 }
 
 #[test]
+#[should_panic]
+fn test_range_overflow_unsigned() {
+    let mut it = u8::MAX..;
+    it.next();
+}
+
+#[test]
+#[should_panic]
+fn test_range_overflow_signed() {
+    let mut it = i8::MAX..;
+    it.next();
+}
+
+#[test]
 fn test_repeat() {
     let mut it = repeat(42);
     assert_eq!(it.next(), Some(42));