improve array_from_fn documenation#104839
improve array_from_fn documenation#104839bors merged 2 commits intorust-lang:masterfrom HintringerFabian:docs_array_from_fn
Conversation
|
r? @scottmcm (rustbot has picked a reviewer for you, use r? to override) |
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
library/core/src/array/mod.rs
Outdated
| /// // inferred to be 5, thus creating array of 5 elements. | ||
| /// let array = core::array::from_fn(|i| i); | ||
| /// | ||
| /// let array: [_; 5] = core::array::from_fn(|i| i); |
There was a problem hiding this comment.
Given the big comment about type inference above this one, I think this example should stay of inferred width
| /// let array: [_; 5] = core::array::from_fn(|i| i); | |
| /// let array = core::array::from_fn(|i| i); |
library/core/src/array/mod.rs
Outdated
| /// // indexes are: 0 1 2 3 4 | ||
| /// assert_eq!(array, [0, 1, 2, 3, 4]); | ||
| /// | ||
| /// let array2: [_; 8] = core::array::from_fn(|i| i * 2); |
There was a problem hiding this comment.
Then it would be good to mention the type annotation on this on to contrast with the first one.
library/core/src/array/mod.rs
Outdated
| /// // indexes are: 0 1 2 3 4 5 6 7 | ||
| /// assert_eq!(array2, [0, 2, 4, 6, 8, 10, 12, 14]); | ||
| /// | ||
| /// let bool_arr: [bool; 5] = core::array::from_fn(|i| i % 2 == 0); |
There was a problem hiding this comment.
And for completeness, maybe show turbofishing for this one?
| /// let bool_arr: [bool; 5] = core::array::from_fn(|i| i % 2 == 0); | |
| /// let bool_arr = core::array::from_fn::<_, 5, _>(|i| i % 2 == 0); |
|
@rustbot ready |
|
@bors r+ rollup=always |
…n, r=scottmcm improve array_from_fn documenation Improves array::from_fn documentation Fixes rust-lang#102609 There were also unresolved comments from [this PR rust-lang#100462](rust-lang#100462), which have been added to my PR
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#104121 (Refine `instruction_set` MIR inline rules) - rust-lang#104675 (Unsupported query error now specifies if its unsupported for local or external crate) - rust-lang#104839 (improve array_from_fn documenation) - rust-lang#104880 ([llvm-wrapper] adapt for LLVM API change) - rust-lang#104899 (rustdoc: remove no-op CSS `#help dt { display: block }`) - rust-lang#104906 (Remove AscribeUserTypeCx) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Improves array::from_fn documentation
Fixes #102609
There were also unresolved comments from this PR #100462, which have been added to my PR