-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Take care of boundaries in Step trait #20249
Comments
cc @nick29581 |
This was intentional and discussed with a bunch of people on irc. The majority felt that an open ended interval should repeat forever, rather than being bounded by the maximum. I feel this could go either way though. Certainly true open-endedness is more efficient, but if you actually rely on the value produced, then it is probably not what the user expects. OTOH, I expect that such iterators would only ever be used with |
But the intervals won't repeat this way -- not with the coming overflow rules and overflow checks. It seems wiser to insert the boundary check manually (and I think to terminate iteration there). What do you think about the Step trait w.r.t this? http://discuss.rust-lang.org/t/a-tale-of-twos-complement/1062 |
I'm not really sure, I think it only makes sense to overflow here (panicking is probably wrong, but then, perhaps not, perhaps it is the user's responsibility not to overflow - that certainly fits with the zero-cost abstraction theme for Rust), which would imply using WrappingInt, or whatever the type will be The more I think about this, the more I think that letting an open ended range end up overflowing is an error of use - i.e., that they should only be taken or whatever. Anything else, means they are not open ended, and if the user wants a range limited by MAX_INT, then they can use |
I agree with @nick29581 that letting a open ended rage overflow is an error of use. Therefore I think it would be the best (in combination with the coming overflowing rules) to let a overflowing rang panic (in both relate and debug bullies). |
Since we have exclusive-end ranges, |
This behavior was changed in a recent stabilization PR to panic on overflow on debug builds (matching the anticipated overflow RFC). |
As long as the panic checks are elided in bounded loops, the performance fallout won't matter that much. |
Watch out for min/max boundaries in the Step trait.
It would be more natural for (0i8..) to produce a finite range, ending with the maximum value 127i8, than to overflow and produce an infinite iterator. Overflow is problematic, (and if we let it stay in, users will rely on the wrap around behavior.) and the Range objects and Step traits need to handle this with care.
The current Step trait supposes that every element has a successor, which is not necessarily true.
The text was updated successfully, but these errors were encountered: