Skip to content

Commit e915b4b

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 94cb3c2 commit e915b4b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/iter/range.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,12 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
10131013

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

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

0 commit comments

Comments
 (0)