Skip to content
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

Add Extend impls for tuples of arity 1 through 12 #132187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

shahn
Copy link
Contributor

@shahn shahn commented Oct 26, 2024

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 26, 2024
@shahn
Copy link
Contributor Author

shahn commented Oct 26, 2024

This was discussed in #85835 (comment) and I want to get that effort started. It's been forever since I contributed to rustc, so please excuse if I did something wrong. If this is deemed OK, I would be happy to follow this up with the same treatmeant for FromIterator and maybe `unzip, too - but those probably deserve their own PR?

@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Oct 30, 2024
@scottmcm
Copy link
Member

r? libs-api

@rustbot rustbot assigned dtolnay and unassigned scottmcm Oct 30, 2024
@dtolnay

This comment was marked as outdated.

@dtolnay dtolnay removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 30, 2024
@rfcbot

This comment was marked as outdated.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 30, 2024
@dtolnay

This comment was marked as outdated.

@rfcbot

This comment was marked as outdated.

@rfcbot rfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 30, 2024
@dtolnay
Copy link
Member

dtolnay commented Oct 30, 2024

@rust-lang/libs-api:
@rfcbot fcp merge

Among other things, this feature makes unzip work for larger (and smaller) tuples.
Among other things, this feature makes collect_into (which is still unstable) work for larger tuples.

  fn main() {
      let iter = std::iter::repeat_n(('a', 'b', 'c'), 3);

-     let mut collection = (Vec::new(), (Vec::new(), Vec::new()));
-     iter.map(|(a, b, c)| (a, (b, c))).collect_into(&mut collection);
-     let (va, (vb, vc)) = collection;
+     let mut collections = (Vec::new(), Vec::new(), Vec::new());
+     iter.collect_into(&mut collections);
+     let (va, vb, vc) = collections;
      println!("{:?}\n{:?}\n{:?}", va, vb, vc);
}

@rfcbot
Copy link

rfcbot commented Oct 30, 2024

Team member @dtolnay 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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 30, 2024
@cuviper
Copy link
Member

cuviper commented Oct 30, 2024

Among other things, this feature makes unzip work for larger (and smaller) tuples.

How so? This doesn't change Iterator::unzip AFAICS, which explicitly operates on pairs -- but either of those pairs could be a nested tuple of arity 1..=12 after this change.

@dtolnay
Copy link
Member

dtolnay commented Oct 30, 2024

You are right. I've updated the motivating use case to use collect_into instead of unzip. Or please let me know if someone knows a better one.

@shahn

This comment was marked as duplicate.

@shahn
Copy link
Contributor Author

shahn commented Oct 31, 2024

I noticed I made a silly mistake, I added tuple impls for not just 12-tuples but 13-tuples accidentally. I am also adding some tests for these impls, but I wonder, is there a good example to verify 13-tuples do not have the Extend impl?

I also want to add the FromIterator<(EA, ...)> for (A, ...) impls. Should these go into a new PR? That would enable this:

    let a = vec![(1, 2, 3), (4, 5, 6), (7, 8, 9)];
    let b: (Vec<_>, Vec<_>, Vec<_>) = a.into_iter().collect();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants