Implement IntoIterator for [&[mut]] Box<[T; N], A>#134021
Implement IntoIterator for [&[mut]] Box<[T; N], A>#134021WaffleLapkin wants to merge 5 commits intorust-lang:mainfrom
IntoIterator for [&[mut]] Box<[T; N], A>#134021Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6f3a44b to
576e704
Compare
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #136572) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@scottmcm anything I can do to move this forward? |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
6bcd9c3 to
72ea626
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
72ea626 to
366152c
Compare
This comment has been minimized.
This comment has been minimized.
33ce55c to
a26c96f
Compare
|
@Mark-Simulacrum I don't think this requires edition handling or FCP, as per the FCP on the previous attempt at doing this:
@rustbot review |
…>` and `[T; N]` They'll be needed for `IntoIterator` impls.
a26c96f to
91e8eb2
Compare
|
I've also removed the complicated unsafe impl for now, making the |
This comment has been minimized.
This comment has been minimized.
Note: this removes warnings, as this breakage was deemed acceptable, see <rust-lang#124108 (comment)>
91e8eb2 to
f65b35f
Compare
There was a problem hiding this comment.
I don't think this requires edition handling or FCP, as per the FCP on the previous attempt at doing this:
I think we do need FCP or at least libs-api meeting nomination to re-confirm that the >1 year old FCP from 2024 is still valid. Maybe a Crater run. This is a breaking change and there was some post-initial-FCP discussion on whether we should do the unsizing impl (#124108 (comment)). Making two breaking changes here feels unfortunate so we should decide upfront which we want, even if we think the change is otherwise reasonable.
I guess the current version of this PR proposes neither option and instead has a dedicated new iterator type (BoxedArrayIntoIter). I think that's entirely net-new surface area, right? It also means we're missing a chunk of impls (e.g., DoubleEndedIterator) that we'd get 'for free' with vec::IntoIter.
|
(for the libs-api nomination) API changesNegative implsThis PR adds the following negative impls (we promise that those types will never implement impl<T, const N: usize> !Iterator for [T; N] {}
impl<I, const N: usize, A: Allocator> !Iterator for Box<[I; N], A> {}
impl<'a, const N: usize, I, A: Allocator> !Iterator for &'a Box<[I; N], A> {}
impl<'a, const N: usize, I, A: Allocator> !Iterator for &'a mut Box<[I; N], A> {}
|
Box<[T; N]> |
&Box<[T; N]> |
&mut Box<[T; N]> |
|
|---|---|---|---|
for loop |
✅ compile error -> T |
✅ compile error -> &T |
✅ compile error -> &mut T |
.into_iter() (edition >= 2021) |
array::IntoIter->BoxedArrayIntoIter (T->T) |
☢️ array::IntoIter->slice::Iter (T->&T) |
☢️ array::IntoIter->slice::IterMut (T->&mut T) |
.into_iter() (edition < 2021) |
☢️ slice::Iter->BoxedArrayIntoIter (&T->T) |
✅ slice::Iter (Item = &T) (unchanged) |
☢️ slice::Iter->slice::IterMut (&T->&mut T) |
Notes:
forloop /<_>::into_iter(box)used to be a compilation error; no breakage here- on
edition >= 2021,.into_iter()used to be extremely inefficient, as it would move out the whole array and put it unto the stack- on
edition >= 2021,.into_iter()on a reference to a box requiresT: Copy
- on
- The emoji I used: ✅ - no breakage,
⚠️ - only iterator type changes, not the item (very unlikely to break something), ☢️ - both change
|
If the
|
No, we aren't missing any impls, since I added all of them :) Also, this PR is compatible with the unsizing idea, with that you would have: struct AllocatedContinuousIntoIter<T: ?Sized, A: Allocator = Global> { ... } // name bikeshedable
type vec::IntoIter<T, A: Allocator> = AllocatedContinuousIntoIter<[T], A>;
type box::BoxedArrayIntoIter<T, const N: usize, A: Allocator> = AllocatedContinuousIntoIter<[T; N], A>;Note that I.e. one of two follow ups is possible:
|
|
@rfcbot merge libs-api |
|
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Revival of #124108