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

Implement tuple<->array convertions via From #97594

Merged
merged 5 commits into from
May 4, 2023

Conversation

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented May 31, 2022

This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths:

impl<T> From<[T; 1]> for (T,) { ... }
impl<T> From<[T; 2]> for (T, T) { ... }
/* ... */
impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... }

impl<T> From<(T,)> for [T; 1] { ... }
impl<T> From<(T, T)> for [T; 2] { ... }
/* ... */
impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... }

IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 31, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2022
@WaffleLapkin
Copy link
Member Author

r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 31, 2022
@rustbot rustbot removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 31, 2022
@WaffleLapkin WaffleLapkin marked this pull request as draft May 31, 2022 19:44
@WaffleLapkin
Copy link
Member Author

@rustbot label -S-waiting-on-review +S-waiting-on-author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2022
library/core/src/tuple.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Jun 1, 2022
@WaffleLapkin
Copy link
Member Author

I've removed () <-> [] impls because they break inference in the following tests:

  • ui/hygiene/hir-res-hygiene.rs
  • ui/suggestions/type-ascription-instead-of-path-2.rs
  • ui/issues/issue-32709.rs

They all basically do the following:

fn f() -> Result<(), ()> {
    Ok(())?; // <--
    Ok(())
}

For this to work you need to infer ?T in Result<(), ?T> having only (): From<?T>. Currently this works because the only impl From for () is the identity impl, so rustc picks it up and infers ?T = ().

IIRC this is not considered a breaking change per rust rules, because it can be fixed by adding types:

fn f() -> Result<(), ()> {
    Ok::<_, ()>(())?; 
    //^^^^^^^^^
    Ok(())
}

However I'm not sure how widespread this pattern is and if this is worth the potential breakage.

@WaffleLapkin WaffleLapkin marked this pull request as ready for review June 2, 2022 13:16
@WaffleLapkin
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 2, 2022
@bors
Copy link
Contributor

bors commented Aug 19, 2022

☔ The latest upstream changes (presumably #98807) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Aug 19, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@camelid
Copy link
Member

camelid commented Feb 11, 2023

ping from triage: What's the status of this PR?

@scottmcm scottmcm added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 12, 2023
@scottmcm
Copy link
Member

Looks like this is old enough that it pre-dates ACPs, so I'll nominate it for libs-api to say what they want.

@WaffleLapkin
Copy link
Member Author

@camelid pretty much what the tags say: this is waiting on a T-libs-api decision

@m-ou-se
Copy link
Member

m-ou-se commented Feb 28, 2023

We briefly discussed this in the libs-api meeting, and we were wondering if there are any motivating use cases.

@ChrisDenton
Copy link
Member

This has passed FCP and the implementation looks good to me. The only thing I would ask for is some tests that exercise this properly. Especially because this is insta stable. Maybe doc tests? Some documentation wouldn't hurt either. E,g,, here,

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented May 3, 2023

📌 Commit de10516 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2023
@ChrisDenton ChrisDenton added relnotes Marks issues that should be documented in the release notes of the next release. and removed needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels May 3, 2023
Manishearth added a commit to Manishearth/rust that referenced this pull request May 3, 2023
…risDenton

Implement tuple<->array convertions via `From`

This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths:
```rust
impl<T> From<[T; 1]> for (T,) { ... }
impl<T> From<[T; 2]> for (T, T) { ... }
/* ... */
impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... }

impl<T> From<(T,)> for [T; 1] { ... }
impl<T> From<(T, T)> for [T; 2] { ... }
/* ... */
impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... }
```

IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
Manishearth added a commit to Manishearth/rust that referenced this pull request May 3, 2023
…risDenton

Implement tuple<->array convertions via `From`

This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths:
```rust
impl<T> From<[T; 1]> for (T,) { ... }
impl<T> From<[T; 2]> for (T, T) { ... }
/* ... */
impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... }

impl<T> From<(T,)> for [T; 1] { ... }
impl<T> From<(T, T)> for [T; 2] { ... }
/* ... */
impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... }
```

IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
Manishearth added a commit to Manishearth/rust that referenced this pull request May 3, 2023
…risDenton

Implement tuple<->array convertions via `From`

This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths:
```rust
impl<T> From<[T; 1]> for (T,) { ... }
impl<T> From<[T; 2]> for (T, T) { ... }
/* ... */
impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... }

impl<T> From<(T,)> for [T; 1] { ... }
impl<T> From<(T, T)> for [T; 2] { ... }
/* ... */
impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... }
```

IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2023
…earth

Rollup of 10 pull requests

Successful merges:

 - rust-lang#97594 (Implement tuple<->array convertions via `From`)
 - rust-lang#105452 (Add cross-language LLVM CFI support to the Rust compiler)
 - rust-lang#105695 (Replace generic thread parker with explicit no-op parker)
 - rust-lang#110371 (rustdoc: restructure type search engine to pick-and-use IDs)
 - rust-lang#110928 (tests: Add tests for LoongArch64)
 - rust-lang#110970 (tidy: remove ENTRY_LIMIT maximum checking and set it to 900)
 - rust-lang#111104 (Update ICU4X to 1.2)
 - rust-lang#111127 (Constify slice flatten method)
 - rust-lang#111146 (rustc_middle: Fix `opt_item_ident` for non-local def ids)
 - rust-lang#111154 (Use builtin FFX isolation for Fuchsia test runner)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 84d8159 into rust-lang:master May 4, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 4, 2023
@WaffleLapkin WaffleLapkin deleted the array_tuple_conv branch May 4, 2023 18:13
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 4, 2023
Fixup "since" dates for `array_tuple_conv` feature

Fixes a mistake from rust-lang#97594
JohnTitor added a commit to JohnTitor/rust that referenced this pull request May 5, 2023
Fixup "since" dates for `array_tuple_conv` feature

Fixes a mistake from rust-lang#97594
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. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.