-
Notifications
You must be signed in to change notification settings - Fork 13.3k
RangeFrom should have an infinite size_hint #42315
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This makes the size_hint from things like `take` more precise.
(rust_highfive has picked a reviewer for you, use r? to override) |
I'm not sure we can say |
let it = (-5..5).map(|x| 100 / x);
assert_eq!(it.size_hint(), (10, Some(10))); Even though iterating it will panic with "attempt to divide by zero" before returning 10 items. A lower-bound of |
📌 Commit 265dce6 has been approved by |
@@ -130,9 +130,10 @@ pub trait Iterator { | |||
/// | |||
/// ``` | |||
/// // an infinite iterator has no upper bound | |||
/// // and the maximum possible lower bound |
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.
Infinite iterators can have any lower bound so I don't think this line should have been added.
Well I guess if |
@bors rollup |
…crichton RangeFrom should have an infinite size_hint Before, ```rust (0..).take(4).size_hint() == (0, Some(4)) ``` With this change, ```rust (0..).take(4).size_hint() == (4, Some(4)) ```
Before,
With this change,