-
Notifications
You must be signed in to change notification settings - Fork 19
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
ACP: IntoIterator for Box<[T]> #263
Comments
For arrays, the edition hack was only about what |
Ahh, I didn't actually know those specifics about the edition hack. I'm honestly not even sure if a hack would be required in this case, but I figured I would make an ACP and talk about it since I remembered that being a contentious issue at the time. Maybe a crater run would just show that I'm being overly cautious. |
It definitely is an analogous situation, that Also, I just remembered that I tried this before and failed due to |
@cuviper Negative impls can now make this possible by |
We discussed this in the libs-api meeting. We're happy with this change since it is clearer the "more correct" behavior for This should be tried with a crater run first. If breaking changes are too significant then a workaround could be prepared for the 2024 edition (it's not yet clear what this would involve, it depends on the crater results). |
IntoIterator for Box<[T]> ACP: rust-lang/libs-team#263 Recommendation per ACP: this should receive a crater run to gauge impact. If there's no impact, it can be merged as-is, but otherwise it will need a similar edition-based workaround to the array implementation. In addition to what was proposed by the ACP, this also adds `IntoIterator for &Box<[T]>` and `IntoIterator for &mut Box<[T]>` to ensure that those work as expected. I also already had to change at least one line in the compiler to account for this change, which isn't a good sign toward whether edition-specific mitigations may be needed, but we'll see.
…fleLapkin Add `IntoIterator` for `Box<[T]>` + edition 2024-specific lints * Adds a similar method probe opt-out mechanism to the `[T;N]: IntoIterator` implementation for edition 2021. * Adjusts the relevant lints (shadowed `.into_iter()` calls, new source of method ambiguity). * Adds some tests. * Took the liberty to rework the logic in the `ARRAY_INTO_ITER` lint, since it was kind of confusing. Based mostly off of rust-lang#116607. ACP: rust-lang/libs-team#263 References rust-lang#59878 Tracking for Rust 2024: rust-lang#123759 Crater run was done here: rust-lang#116607 (comment) Consensus afaict was that there is too much breakage, so let's do this in an edition-dependent way much like `[T; N]: IntoIterator`.
Add `IntoIterator` for `Box<[T]>` + edition 2024-specific lints * Adds a similar method probe opt-out mechanism to the `[T;N]: IntoIterator` implementation for edition 2021. * Adjusts the relevant lints (shadowed `.into_iter()` calls, new source of method ambiguity). * Adds some tests. * Took the liberty to rework the logic in the `ARRAY_INTO_ITER` lint, since it was kind of confusing. Based mostly off of #116607. ACP: rust-lang/libs-team#263 References #59878 Tracking for Rust 2024: rust-lang/rust#123759 Crater run was done here: rust-lang/rust#116607 (comment) Consensus afaict was that there is too much breakage, so let's do this in an edition-dependent way much like `[T; N]: IntoIterator`.
Add `IntoIterator` for `Box<[T]>` + edition 2024-specific lints * Adds a similar method probe opt-out mechanism to the `[T;N]: IntoIterator` implementation for edition 2021. * Adjusts the relevant lints (shadowed `.into_iter()` calls, new source of method ambiguity). * Adds some tests. * Took the liberty to rework the logic in the `ARRAY_INTO_ITER` lint, since it was kind of confusing. Based mostly off of #116607. ACP: rust-lang/libs-team#263 References #59878 Tracking for Rust 2024: rust-lang/rust#123759 Crater run was done here: rust-lang/rust#116607 (comment) Consensus afaict was that there is too much breakage, so let's do this in an edition-dependent way much like `[T; N]: IntoIterator`.
Proposal
Problem statement
Right now, calling
<Box<[T]>>::into_iter
has the same issue that<[T; N]>::into_iter
had prior to Rust edition 2021: it takes the box by reference instead of by value, since it implicitly refers to the implementation of<&[T]>::into_iter
.However, this can be done by-value by converting the
Box
to aVec
first, returningvec::IntoIter
instead.Motivating examples or use cases
Boxed slices can be used in many of the same places as
Vec
s, and they have much of the same use cases, which means they should have the same behaviour.Solution sketch
IntoIterator
forBox<[T]>
would be implemented, providing the following definition:However, this would likely require per-edition inference like the exception made for
IntoIterator for [T; N]
, only properly working on an edition bump. Namely, on the current edition,<Box<[T]>>::into_iter
would call the<&[T]>::into_iter
definition instead, and only on future editions would it call<Box<[T]>>::into_iter
. Older-edition code would have to callinto_vec().into_iter()
instead.Alternatives
The main alternative is to do nothing, since the possible alternative is only slightly longer.
(Old edition example):
(New edition example):
Links and related work
None known.
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: