-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add InfiniteIterator trait #146668
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
base: master
Are you sure you want to change the base?
Add InfiniteIterator trait #146668
Conversation
58acbaf
to
722ad22
Compare
This comment has been minimized.
This comment has been minimized.
This enables more ExactSizeIterator instances, specifically, those for `Take`, where the sub-iterator is infinite, and `Zip` where the one sub-iterator is infinite, and the other is exact sized. Previously, in rust-lang#146642, I sought to add specific instances for `Zip<Repeat<A>, I>` and its symmatrical mirror. Introducing `InfiniteIterator` provides much broader support for `ExactSizeIterator`. For example, ```rust [1, 2, 3].into_iter().chain(repeat(1)).take(5) ``` Will now happily resolve to an instance of `ExactSizeIterator`. The downside of this approach is that, to avoid the overlapping instance with `Zip`, I had to introduce a negative trait bound, which, IIUC, isn't available outside of the compiler. If anyone knows of a better way to handle the overlapping instances, or a way I can expose something which triggers the negative instance, that would be very helpful. There's also a missing symmetrical instance for `Chain`. Solutions are welcome.
722ad22
to
13a0203
Compare
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.
Oh, please don't use negative bounds! They are for internal trait solver tests only!
The job Click to see the possible cause of the failure (guessed by this bot)
|
@fmease yeah trust me I didn't want to use them. I need this kind of thing to be accepted:
I know no type will ever implement |
This definitely needs an ACP, and should not be instantly stable. |
I didn't really look at the negative impls (tho adding any negative impls is an incredibly strong SemVer promise and shouldn't be taken lightly), I'm mostly concerned with the use of negative bounds. These are more than internal; they are so internal that we don't even advertise the name of their lang feature in diagnostics on the nightly channel. Their implementation is not complete (maybe even unsound), they don't have any backing RFC or unofficial proposal. They should not be used inside cc @compiler-errors for a second opinion. |
Yeah negative bounds are definitely not stable enough to use even if we are hiding their use behind public facing traits or something. |
Ack -- sorry for blurring the line between impls and bounds. |
A previous attempt: #90093 |
As Josh mentioned, please open an ACP with this proposal, it's an issue template at https://github.com/rust-lang/libs-team/issues. @rustbot author |
Reminder, once the PR becomes ready for a review, use |
This enables more ExactSizeIterator instances, specifically, those
for
Take
, where the sub-iterator is infinite, andZip
whereone sub-iterator is infinite, and the other is exact sized.
Previously, in #146642,
I sought to add specific instances for
Zip<Repeat<A>, I>
and itssymmatrical mirror.
Introducing
InfiniteIterator
provides much broader support forExactSizeIterator
.For example,
Will now happily resolve to an instance of
ExactSizeIterator
.The downside of this approach is that, to avoid the overlapping instance
with
Zip
, I had to introduce a negative trait bound, which, IIUC,isn't available outside of the compiler.
If anyone knows of a better way to handle the overlapping instances, or
a way I can expose something which triggers the negative instance, that
would be very helpful.
There's also a missing symmetrical instance for
Chain
. Solutionsare welcome.