-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Box<[T]> should have an IntoIter implementation. #59878
Comments
Unfortunately this has the same issue as #25725: Whatever we end up deciding should probably apply to both. CC @rust-lang/libs |
Unlike with arrays though, this case has a work-around in converting though |
So we could add the implementation today, using |
The user could work around this by going through But if |
@scottmcm Yes, the implementation is easy and does not require a new type. The concern is only in the change being breaking. |
@SimonSapin Do you think it would be a good idea to add a future-incompatibility lint for this, like we did for the |
FWIW, I just tried adding // library/alloc/src/boxed.rs
#[stable(feature = "boxed_slice_into_iter", since = "1.53.0")]
impl<T, A> IntoIterator for Box<[T], A> {
type Item = T;
type IntoIter = crate::vec::IntoIter<T, A>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
#[stable(feature = "boxed_array_into_iter", since = "1.53.0")]
impl<T, A, const N: usize> IntoIterator for Box<[T; N], A> {
type Item = T;
type IntoIter = crate::vec::IntoIter<T, A>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
This has to do with |
We discussed this in the @rust-lang/libs meeting today. Our consensus was that we'd be happy to see this impl, as long as doing so was possible and wouldn't break backwards compatibility. It's possible that the machinery proposed for supporting The coherence issue @cuviper reported seems orthogonal to that, though. |
@yaahc This might be another good use case for your negative trait implementation feature. E.g. |
Are there any updates on this? It does seem like a waste of the edition update if this isn't going into Rust 2021. There're a number of places in our codebase where we're doing I wouldn't mind spending some time to get this working, if we're just waiting for someone to get around to writing the implementation. (But I've never contributed to Rust before, so I might need some guidance.) |
I believe the edition cutoff has already passed quite a few months ago, so I doubt it's possible for this to make it into the 2021 edition but there may be some ways we can make it work backwards compatibly as @joshtriplett mentioned. AFAIK this is just waiting on someone to get around to writing the implementation so if this is something you're interested in please take a crack at it @btzy! |
…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`.
This has now happened in: ...and is expected to stabilize with Rust 1.80. So we can close this issue. |
Right now the only way to move out of a
Box<[T]>
is usinginto_vec
, which is a bit inconvenient. Is there any reasonBox<[T]>
shouldn't implementIntoIter
?The text was updated successfully, but these errors were encountered: