about summary refs log tree commit diff
path: root/library/core
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-10-23 14:48:13 -0700
committerGitHub <noreply@github.com>2022-10-23 14:48:13 -0700
commitacc269d65b9dd41a0a3c74e5c528b6e65e193e58 (patch)
tree8af54ee241ba9de8358a79b2bc99fab84f0e3428 /library/core
parent7fcf850d7942804990a1d2e3fe036622a0fe4c74 (diff)
parent289ad1ac3882135fd3bc1387536978248dead9da (diff)
downloadrust-acc269d65b9dd41a0a3c74e5c528b6e65e193e58.tar.gz
rust-acc269d65b9dd41a0a3c74e5c528b6e65e193e58.zip
Rollup merge of #100462 - zohnannor:master, r=thomcc
Clarify `array::from_fn` documentation

I've seen quite a few of people on social media confused of where the length of array is coming from in the newly stabilized `array::from_fn` example.

This PR tries to clarify the documentation on this.
Diffstat (limited to 'library/core')
-rw-r--r--library/core/src/array/mod.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index 04dd821efde..eae0e1c7618 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -32,6 +32,10 @@ pub use iter::IntoIter;
 /// # Example
 ///
 /// ```rust
+/// // type inference is helping us here, the way `from_fn` knows how many
+/// // elements to produce is the length of array down there: only arrays of
+/// // equal lengths can be compared, so the const generic parameter `N` is
+/// // inferred to be 5, thus creating array of 5 elements.
 /// let array = core::array::from_fn(|i| i);
 /// assert_eq!(array, [0, 1, 2, 3, 4]);
 /// ```