-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Better docs for copy_from_slice & clone_from_slice #51701
Conversation
It elaborates over why we have to slice the 4-size src to 2-size (same as dst).
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TimNN (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libcore/slice/mod.rs
Outdated
@@ -1607,6 +1611,10 @@ impl<T> [T] { | |||
/// let src = [1, 2, 3, 4]; | |||
/// let mut dst = [0, 0]; | |||
/// | |||
/// // Note: the slices must be the same length, so |
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.
Nit: The line breaks look somewhat strange here, the first two lines break at a different width than the last two lines.
Thanks for your PR, @anirudhb! I'm sorry that I didn't get to this PR sooner, but I was on vacation the past week. The PR generally looks good to me, however I'll defer to @steveklabnik for final approval. |
@TimNN I've fixed it so that it looks slightly better, and it is now on three lines. |
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@anirudhb: 🔑 Insufficient privileges: not in try users |
1 similar comment
@anirudhb: 🔑 Insufficient privileges: not in try users |
I've restarted the travis build manually. |
Thank you, I think it was an unrelated error to the documentation change. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ping from triage, @steveklabnik: This PR requires your review! |
Ping from triage! This PR needs a review, can @steveklabnik or someone else from @rust-lang/docs review this? |
src/libcore/slice/mod.rs
Outdated
@@ -1541,6 +1541,9 @@ impl<T> [T] { | |||
/// let src = [1, 2, 3, 4]; | |||
/// let mut dst = [0, 0]; | |||
/// | |||
/// // Note: the slices must be the same length, so you can slice the | |||
/// // source to be the same size. Here we slice the source, four elements, |
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.
This all make sense to me, though I'm a little confused by this phrase:
so you can slice the source to be the same size
...because in some scenarios, you'll need to slice the destination to match the length of the source.
I think this would be good enough:
Note: The slices must be the same length, otherwise this method will panic. Here we slice the source, four elements, to two, the same size as the destination slice.
What do you think?
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 think changing it to "so you can slice the source or the destination to be the same size." would be fine.
Edit: added in most recent commit
I still find the added comments difficult to read/understand. |
src/libcore/slice/mod.rs
Outdated
@@ -1541,6 +1541,9 @@ impl<T> [T] { | |||
/// let src = [1, 2, 3, 4]; | |||
/// let mut dst = [0, 0]; | |||
/// | |||
/// // Note: the slices must be the same length, so you can slice the source | |||
/// // or the destination to be the same size. Here we slice the source, four elements, |
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.
the slices must be the same length, so you can slice the source or the destination to be the same size
I spoke with a couple other documentation people and we agreed that this would be better worded as:
Because the slices must be the same length, we'll need to slice the source slice from four elements to two. It will panic if we don't do this.
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.
Done.
thanks! @bors r+ rollup |
📌 Commit 4b51484 has been approved by |
Better docs for copy_from_slice & clone_from_slice I copy-pasted the text from clone_from_slice to copy_from_slice 😄 @steveklabnik feel free to suggest changes. edit: closes rust-lang#49769
Rollup of 5 pull requests Successful merges: - #51701 (Better docs for copy_from_slice & clone_from_slice) - #52231 (Fix typo in error message E0277) - #52233 (Improve lint handling in rustdoc) - #52238 (Avoid unwrapping in PanicInfo doc example.) - #52241 (Fix typo in E0433 docs) Failed merges: r? @ghost
I copy-pasted the text from clone_from_slice to copy_from_slice 😄
@steveklabnik feel free to suggest changes.
edit: closes #49769