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

improve array_from_fn documenation #104839

Merged
merged 2 commits into from
Nov 26, 2022

Conversation

HintringerFabian
Copy link
Contributor

Improves array::from_fn documentation
Fixes #102609

There were also unresolved comments from this PR #100462, which have been added to my PR

@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2022

r? @scottmcm

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 24, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Thanks for sending a PR! This looks like a good improvement; I just have a couple of tweak requests.

@rustbot author

(Once you'd like me to look at this again, use @rustbot ready to update the labels.)

@@ -36,8 +37,18 @@ pub use iter::IntoIter;
/// // 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);
///
/// let array: [_; 5] = core::array::from_fn(|i| i);
Copy link
Member

Choose a reason for hiding this comment

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

Given the big comment about type inference above this one, I think this example should stay of inferred width

Suggested change
/// let array: [_; 5] = core::array::from_fn(|i| i);
/// let array = core::array::from_fn(|i| i);

/// assert_eq!(array, [0, 1, 2, 3, 4]);
///
/// let array2: [_; 8] = core::array::from_fn(|i| i * 2);
Copy link
Member

Choose a reason for hiding this comment

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

Then it would be good to mention the type annotation on this on to contrast with the first one.

/// // 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);
Copy link
Member

Choose a reason for hiding this comment

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

And for completeness, maybe show turbofishing for this one?

Suggested change
/// 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 rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2022
@HintringerFabian
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2022
@scottmcm
Copy link
Member

@bors r+ rollup=always

@bors
Copy link
Contributor

bors commented Nov 26, 2022

📌 Commit 69d562d has been approved by scottmcm

It is now in the queue for this repository.

@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 Nov 26, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 26, 2022
…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
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 26, 2022
…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
@bors bors merged commit 1fc83ae into rust-lang:master Nov 26, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

array::from_fn behavior is unclear from documentation
4 participants