Skip to content

Commit 0cae867

Browse files
committed
(intentionally broken) add overflow checks to legacy RangeFrom
tests will fail, but this is meant for checking how it affects compile times, which shouldn't be impacted by the broken logic
1 parent 80e7831 commit 0cae867

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/src/iter/range.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,11 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
10141014

10151015
#[inline]
10161016
fn next(&mut self) -> Option<A> {
1017+
if crate::intrinsics::overflow_checks() {
1018+
self.start = Step::forward(self.start.clone(), 1);
1019+
return Some(self.start.clone());
1020+
}
1021+
10171022
let n = Step::forward(self.start.clone(), 1);
10181023
Some(mem::replace(&mut self.start, n))
10191024
}
@@ -1025,6 +1030,12 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
10251030

10261031
#[inline]
10271032
fn nth(&mut self, n: usize) -> Option<A> {
1033+
if crate::intrinsics::overflow_checks() {
1034+
let plus_n = Step::forward(self.start.clone(), n);
1035+
self.start = Step::forward(plus_n.clone(), 1);
1036+
return Some(self.start.clone());
1037+
}
1038+
10281039
let plus_n = Step::forward(self.start.clone(), n);
10291040
self.start = Step::forward(plus_n.clone(), 1);
10301041
Some(plus_n)

0 commit comments

Comments
 (0)