diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 66d05d81d80c..a9487b7f46db 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 27eb25537f31..7671ef2e8b98 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -915,6 +915,20 @@ fn test_range_step() { assert_eq!((isize::MIN..isize::MAX).step_by(1).size_hint(), (usize::MAX, Some(usize::MAX))); } +#[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);