-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
#[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>> |
There was a problem hiding this comment.
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]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bors r+ rollup=never |
📌 Commit 922abfafc367cec3a87a8bf87d1d9a653f47908a has been approved by |
⌛ Testing commit 922abfafc367cec3a87a8bf87d1d9a653f47908a with merge 26e9d09eab6c91ecc5e49dcfc6c7fb514cd1b77f... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
…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.
922abfa
to
b96b9b4
Compare
📌 Commit b96b9b4 has been approved by |
⌛ Testing commit b96b9b4 with merge 75920bfb43c87df5c6a46c29386ea4ff8a304ef2... |
💔 Test failed - checks-actions |
I don't see anything in https://github.com/rust-lang-ci/rust/runs/4402890723 that actually failed? Looks like @bors retry |
☀️ Test successful - checks-actions |
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 |
…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
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
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