Skip to content

Commit d917112

Browse files
committed
Stabilize core::array::from_fn
1 parent 512a328 commit d917112

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

library/core/src/array/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ pub use iter::IntoIter;
3131
/// # Example
3232
///
3333
/// ```rust
34-
/// #![feature(array_from_fn)]
35-
///
3634
/// let array = core::array::from_fn(|i| i);
3735
/// assert_eq!(array, [0, 1, 2, 3, 4]);
3836
/// ```
3937
#[inline]
40-
#[unstable(feature = "array_from_fn", issue = "89379")]
41-
pub fn from_fn<F, T, const N: usize>(mut cb: F) -> [T; N]
38+
#[stable(feature = "array_from_fn", since = "1.63.0")]
39+
pub fn from_fn<T, const N: usize, F>(mut cb: F) -> [T; N]
4240
where
4341
F: FnMut(usize) -> T,
4442
{
@@ -65,7 +63,7 @@ where
6563
/// # Example
6664
///
6765
/// ```rust
68-
/// #![feature(array_from_fn)]
66+
/// #![feature(array_try_from_fn)]
6967
///
7068
/// let array: Result<[u8; 5], _> = std::array::try_from_fn(|i| i.try_into());
7169
/// assert_eq!(array, Ok([0, 1, 2, 3, 4]));
@@ -80,8 +78,8 @@ where
8078
/// assert_eq!(array, None);
8179
/// ```
8280
#[inline]
83-
#[unstable(feature = "array_from_fn", issue = "89379")]
84-
pub fn try_from_fn<F, R, const N: usize>(cb: F) -> ChangeOutputType<R, [R::Output; N]>
81+
#[unstable(feature = "array_try_from_fn", issue = "89379")]
82+
pub fn try_from_fn<R, const N: usize, F>(cb: F) -> ChangeOutputType<R, [R::Output; N]>
8583
where
8684
F: FnMut(usize) -> R,
8785
R: Try,

library/core/tests/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn array_try_from_fn() {
388388
let array = core::array::try_from_fn(|i| Ok::<_, SomeError>(i));
389389
assert_eq!(array, Ok([0, 1, 2, 3, 4]));
390390

391-
let another_array = core::array::try_from_fn::<_, Result<(), _>, 2>(|_| Err(SomeError::Foo));
391+
let another_array = core::array::try_from_fn::<Result<(), _>, 2, _>(|_| Err(SomeError::Foo));
392392
assert_eq!(another_array, Err(SomeError::Foo));
393393
}
394394

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#![feature(float_minimum_maximum)]
3636
#![feature(future_join)]
3737
#![feature(future_poll_fn)]
38-
#![feature(array_from_fn)]
38+
#![feature(array_try_from_fn)]
3939
#![feature(hasher_prefixfree_extras)]
4040
#![feature(hashmap_internals)]
4141
#![feature(try_find)]

0 commit comments

Comments
 (0)