-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Can't use DoubleEndedIterator for inclusive ranges #66195
Comments
To give some context, I am currently learning Rust via Jetbrain Academy, which is an adaptation of the rustlings course. In the part about Ranges, they provide this code as an example fn main() {
for number in (1..4).rev() {
println!("{}!", number);
}
println!("LIFTOFF!!!");
} I started toying with it, modified the range to I understand that this compromise was made due to #36386, but as someone who's just learning rust now, the issue I ran into was a massive WTF moment for me, probably a much bigger one than if I had tried to do I think fixing this issue could help Rust with its goal to flatten the learning curve. |
I just ran into this too, pretty annoying. |
Not going to happen because of rust/library/core/src/iter/range.rs Lines 903 to 936 in 495203b
|
I wonder if it makes sense to panic in ExactSizeIterator if the range is too big for the platform. Pretty sure that makes the type unusable though. |
Code:
Error:
I think Rust is not getting safer without ExactSizeIterator implementation for RangeInclusive. The behavior like the one above is not obvious for average Rust coder. Moreover, the workaround exists:
related: #36386
The text was updated successfully, but these errors were encountered: