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

Make array::{try_from_fn, try_map} and Iterator::try_find generic over Try #91286

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Nov 27, 2021

Fixes #85115

This only updates unstable functions.

array::try_map didn't actually exist before; this adds it under the still-open tracking issue #79711 from the old PR #79713.

Tracking issue for the new trait: #91285

This would also solve the return type question in for the proposed Iterator::try_reduce in #87054

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(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 Nov 27, 2021
@scottmcm scottmcm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 27, 2021
#[inline]
#[unstable(feature = "try_find", reason = "new API", issue = "63178")]
fn try_find<F, R, E>(&mut self, f: F) -> Result<Option<Self::Item>, E>
fn try_find<F, R>(&mut self, f: F) -> ChangeOutputType<R, Option<Self::Item>>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy that this gets to remove the superfluous E here. I had previously added it in ca92b5a#diff-c552b2bf18fb3212fe93dd601ce487badf5e50faf9aeed4db7b0f6c22571ef01R2416 to make the ugly bound below happy -- and making that bound not so overly-restrictive is the genesis of this PR.

/// assert_eq!(c, Some(a));
/// ```
#[unstable(feature = "array_try_map", issue = "79711")]
pub fn try_map<F, R>(self, f: F) -> ChangeOutputType<R, [R::Output; N]>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're curious, rustdoc expands out the type alias here. Yes, it's not friendly once expanded:
image

@joshtriplett
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Dec 2, 2021

📌 Commit 922abfafc367cec3a87a8bf87d1d9a653f47908a has been approved by joshtriplett

@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 Dec 2, 2021
@bors
Copy link
Contributor

bors commented Dec 2, 2021

⌛ Testing commit 922abfafc367cec3a87a8bf87d1d9a653f47908a with merge 26e9d09eab6c91ecc5e49dcfc6c7fb514cd1b77f...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 2, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 2, 2021
…r Try

Fixes 85115

This only updates unstable functions.

`array::try_map` didn't actually exist before, despite the tracking issue 79711 still being open from the old PR 79713.
@scottmcm
Copy link
Member Author

scottmcm commented Dec 2, 2021

Doh, conflicted with myself (#91301). I've removed the no-longer-needed #![feature] (and rebased).

@bors r=joshtriplett

@bors
Copy link
Contributor

bors commented Dec 2, 2021

📌 Commit b96b9b4 has been approved by joshtriplett

@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 Dec 2, 2021
@bors
Copy link
Contributor

bors commented Dec 3, 2021

⌛ Testing commit b96b9b4 with merge 75920bfb43c87df5c6a46c29386ea4ff8a304ef2...

@bors
Copy link
Contributor

bors commented Dec 3, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 3, 2021
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@scottmcm
Copy link
Member Author

scottmcm commented Dec 3, 2021

I don't see anything in https://github.com/rust-lang-ci/rust/runs/4402890723 that actually failed?

Looks like dist-x86_64-apple just didn't run at all.

@bors retry

@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 Dec 3, 2021
@bors
Copy link
Contributor

bors commented Dec 3, 2021

⌛ Testing commit b96b9b4 with merge d47a6cc...

@bors
Copy link
Contributor

bors commented Dec 3, 2021

☀️ Test successful - checks-actions
Approved by: joshtriplett
Pushing d47a6cc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 3, 2021
@bors bors merged commit d47a6cc into rust-lang:master Dec 3, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 3, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d47a6cc): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@scottmcm scottmcm deleted the residual-trait branch December 3, 2021 18:33
bors added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2022
…ttmcm

Stabilize `array_from_fn`

## Overall

Stabilizes `core::array::from_fn` ~~and `core::array::try_from_fn`~~ to allow the creation of custom infallible ~~and fallible~~ arrays.

Signature proposed for stabilization here, tweaked as requested in the meeting:

```rust
// in core::array

pub fn from_fn<T, const N: usize, F>(_: F) -> [T; N];
```

Examples in https://doc.rust-lang.org/nightly/std/array/fn.from_fn.html

## History

* On 2020-08-17, implementation was [proposed](rust-lang#75644).
* On 2021-09-29, tracking issue was [created](rust-lang#89379).
* On 2021-10-09, the proposed implementation was [merged](bc8ad24).
* On 2021-12-03, the return type of `try_from_fn` was [changed](rust-lang#91286 (comment)).

## Considerations

* It is being assumed that indices are useful and shouldn't be removed from the callbacks
* The fact that `try_from_fn` returns an unstable type `R: Try` does not prevent stabilization. Although I'm honestly not sure about it.
* The addition or not of repeat-like variants is orthogonal to this PR.

These considerations are not ways of saying what is better or what is worse. In reality, they are an attempt to move things forward, anything really.

cc rust-lang#89379
workingjubilee pushed a commit to tcdi/postgrestd that referenced this pull request Sep 15, 2022
Stabilize `array_from_fn`

## Overall

Stabilizes `core::array::from_fn` ~~and `core::array::try_from_fn`~~ to allow the creation of custom infallible ~~and fallible~~ arrays.

Signature proposed for stabilization here, tweaked as requested in the meeting:

```rust
// in core::array

pub fn from_fn<T, const N: usize, F>(_: F) -> [T; N];
```

Examples in https://doc.rust-lang.org/nightly/std/array/fn.from_fn.html

## History

* On 2020-08-17, implementation was [proposed](rust-lang/rust#75644).
* On 2021-09-29, tracking issue was [created](rust-lang/rust#89379).
* On 2021-10-09, the proposed implementation was [merged](rust-lang-ci/rust@bc8ad24).
* On 2021-12-03, the return type of `try_from_fn` was [changed](rust-lang/rust#91286 (comment)).

## Considerations

* It is being assumed that indices are useful and shouldn't be removed from the callbacks
* The fact that `try_from_fn` returns an unstable type `R: Try` does not prevent stabilization. Although I'm honestly not sure about it.
* The addition or not of repeat-like variants is orthogonal to this PR.

These considerations are not ways of saying what is better or what is worse. In reality, they are an attempt to move things forward, anything really.

cc rust-lang/rust#89379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

Decide on generic-ness of functions like Iterator::try_find and array::try_map
7 participants