Skip to content

Commit 3448d96

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 fa8b3be commit 3448d96

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/iter/range.rs

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

10151015
#[inline]
10161016
fn next(&mut self) -> Option<A> {
1017+
#[cfg(not(bootstrap))]
1018+
if crate::intrinsics::overflow_checks() {
1019+
self.start = Step::forward(self.start.clone(), 1);
1020+
return Some(self.start.clone());
1021+
}
1022+
10171023
let n = Step::forward(self.start.clone(), 1);
10181024
Some(mem::replace(&mut self.start, n))
10191025
}
@@ -1025,6 +1031,13 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
10251031

10261032
#[inline]
10271033
fn nth(&mut self, n: usize) -> Option<A> {
1034+
#[cfg(not(bootstrap))]
1035+
if crate::intrinsics::overflow_checks() {
1036+
let plus_n = Step::forward(self.start.clone(), n);
1037+
self.start = Step::forward(plus_n.clone(), 1);
1038+
return Some(self.start.clone());
1039+
}
1040+
10281041
let plus_n = Step::forward(self.start.clone(), n);
10291042
self.start = Step::forward(plus_n.clone(), 1);
10301043
Some(plus_n)

0 commit comments

Comments
 (0)