Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ macro_rules! step_impl_unsigned {
}

#[inline]
#[rustc_inherit_overflow_checks]
fn add_one(&self) -> Self {
*self + 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add::add(*self, 1) is what @alexcrichton meant. Similar situation on the rest.

}

#[inline]
#[rustc_inherit_overflow_checks]
fn sub_one(&self) -> Self {
*self - 1
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't these tests fail if compiled in release mode?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that's a good point. Then these have to be run-fail with the overflow checking forced on (see src/test/run-fail/*overflow*.rs).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #36372 for reference on making these tests.

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);
Expand Down