-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add a note about overflowing in the RangeFrom
iterator
#32592
Conversation
The idea came from reddit: https://www.reddit.com/r/rust/comments/4cfea1/i_dont_understand_why_this_for_loop_is_giving_me/. |
I'm not sure adding a note like this is the best solution (which would be to fix the issue :p). |
@@ -1539,6 +1539,10 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> { | |||
/// | |||
/// See the [`contains()`](#method.contains) method for its characterization. | |||
/// | |||
/// Note: No overflow checking is done for the iterator implementation; if you | |||
/// use an integer range and the integer overflows, it will panic in debug mode | |||
/// and create an endless loop in release mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the wording can be tweaked here slightly along the lines of:
- It will likely panic in debug mode, but isn't necessarily guaranteed to do so at this time.
- This will only create an endless loop for the range
0..
, right? Something like1..
will overflow to 0 at some point which should stop iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's always an endless loop (if it doesn't panic), the implementation does not have a path that returns None
: https://github.com/tbu-/rust/blob/ad9f9a563ed82df5ea82bc32497dd986614bdee7/src/libcore/iter.rs#L4642-L4654.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. I guess I'm basically thinking we want to word this in such a way so that we're not committing to anything, just noting the current behavior.
ad9f9a5
to
6acd90f
Compare
@alexcrichton Reworded the note a bit. Is that fine? |
Add a note about overflowing in the `RangeFrom` iterator
No description provided.