Skip to content

Tracking Issue for edition-dependent IntoIterator for arrays #84513

Open

Description

@m-ou-se

Once edition 2021 is stable:

  • Update examples like this to use arrays by value. (Some(&1) → Some(1) etc.)
    • Update examples to no longer avoid iterating arrays. (Many doctest examples are using iterators over e.g. &i32 instead of just i32.)
  • Remove about 200 usages of .iter().copied() and .iter().cloned() from examples and tests.

Unresolved questions:

  • Do something about the 'copying large arrays' footgun. (Add IntoIterator implementation for Box<[T; N]> etc? Add lint about big copies?)

Activity

  1. added
    T-langRelevant to the language team
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Apr 24, 2021
  2. cuviper commented on Apr 24, 2021

    @cuviper
    Member

    Add IntoIterator implementation for Box<[T; N]> etc?

    I think it would be great if that could produce vec::IntoIter<T>, but it gave me an upstream coherence error when I tried in #59878 (comment), core being upstream of alloc.

         = note: conflicting implementation in crate `core`:
                 - impl<I> IntoIterator for I
                   where I: Iterator;
         = note: upstream crates may add a new impl of trait `core::iter::Iterator` for type `[_; _]` in future versions
    
  3. mominul commented on May 20, 2021

    @mominul
    Contributor

    I'd like to tackle the standard library changes first!
    @rust-highfive assign

  4. weihanglo commented on May 21, 2021

    @weihanglo
    Member

    Also suggest just removing .into_iter() in for a in [1, 2, 3].into_iter(), since that now works on all editions.

    Since for loop are converted into loop in HIR, is it still possible implementing this as a late pass lint rule?

  5. k0pernicus commented on May 21, 2021

    @k0pernicus
    Contributor

    I could work on updating the array_into_iter lint.
    However, as I never touched to this part before I may have some questions later...

  6. nikomatsakis commented on May 24, 2021

    @nikomatsakis
    Contributor

    I'm going to break this issue apart into sub-issues to help in people signing up for specific bits!

  7. m-ou-se commented on May 24, 2021

    @m-ou-se
    MemberAuthor

    I'd like to tackle the standard library changes first!

    @mominul Which changes specifically do you mean? Have you started working on these?

  8. mominul commented on May 24, 2021

    @mominul
    Contributor

    @m-ou-se I haven't started yet, but I intend to work on the Update standard library checklist items:

    • Remove usages of array::IntoIter::new.
    • Update examples to no longer avoid iterating arrays. (Many doctest examples are using iterators over e.g. &i32 instead of just i32.)
    • Update expressions like like .chain(array.iter().cloned()) to just .chain(array) since that now works on all editions. (Same for zip, extend etc.)
    • Use .extend(array) and from_iter(array) wherever that simplifies things.
    • Remove arrays do not yet implement IntoIterator message from Iterator trait.
  9. m-ou-se commented on May 25, 2021

    @m-ou-se
    MemberAuthor

    Thanks! Since we're running a bit short on time for the edition changes, I'm implementing the most important ones today. Hope you don't mind. I'll add the PR numbers in the first comment above, so take a look there before you start implementing anything to avoid doing work twice.

  10. added a commit that references this issue on May 26, 2021
  11. mominul commented on May 26, 2021

    @mominul
    Contributor

    @m-ou-se Thanks, I will! 😊

  12. 8 remaining items

  13. joshtriplett commented on Jul 20, 2022

    @joshtriplett
    Member

    The lang portion of this has stabilized and shipped, so un-tagging lang. libs-api may wish to continue tracking this for the proposed documentation changes.

  14. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Apr 6, 2024
  15. added a commit that references this issue on May 6, 2025
  16. added a commit that references this issue on May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-edition-2021Area: The 2021 editionA-iteratorsArea: IteratorsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions