-
Notifications
You must be signed in to change notification settings - Fork 13.3k
size_hint
should be able to return a lower bound that is infinite
#18751
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
Comments
It's not incorrect to return |
While it is not incorrect for the purposes of allocation, we might want to use |
@vks That should trigger a panic anyway. If it doesn't, it's a bug. |
It will end up triggering an immediate out-of-memory error once #18726 is fixed, but it doesn't at the moment. |
It does, but it is a generic capacity overflow: let v: Vec<_> = repeat(1u32).collect(); gives task '<main>' panicked at 'capacity overflow',
/Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/option.rs:315 We could have a 'nicer' more specific panic. |
That's because it's doing
That would imply an extra branch in a performance critical code path, and a third failure case as part of the API. I don't think it offers much value in return. |
In theory this could be done at compile time, then there would be no performance impact. (But then, we probably couldn't use How is the panic message part of the API? You cannot catch panics. If you don't want want a different panic, it could also be a lint. |
It could sometimes be done at compile-time (type-based, and not catching instances that are possibly infinite at runtime), but Rust doesn't have the metaprogramming features to do that.
You can catch panics. They are exceptions, nothing more or less - Rust pays a very high cost to make it possible to catch them instead of aborting the process. There's currently the restriction of only being able to catch them at task boundaries for memory safety.
I don't think library related stuff belongs in a lint built-in to the compiler. IMO, it's not a widely applicable warning anyway. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#677 |
Taken from the standard library:
Some iterators are infinite,
size_hint
should be able to return(None, None)
for that. This warrants changing the type signature to(Option<uint>, Option<uint>)
.The text was updated successfully, but these errors were encountered: