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

Better docs for copy_from_slice & clone_from_slice #51701

Merged
merged 5 commits into from
Jul 11, 2018

Conversation

anirudhb
Copy link
Contributor

@anirudhb anirudhb commented Jun 22, 2018

I copy-pasted the text from clone_from_slice to copy_from_slice 😄

@steveklabnik feel free to suggest changes.

edit: closes #49769

It elaborates over why we have to slice the 4-size src to 2-size (same as dst).
@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2018
@anirudhb anirudhb changed the title Better docs for copy_from_slice & clone_from_slice (closes #49769) Better docs for copy_from_slice & clone_from_slice Jun 22, 2018
@@ -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
Copy link
Contributor

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.

@TimNN
Copy link
Contributor

TimNN commented Jun 24, 2018

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.

r? @steveklabnik

@rust-highfive rust-highfive assigned steveklabnik and unassigned TimNN Jun 24, 2018
@anirudhb
Copy link
Contributor Author

@TimNN I've fixed it so that it looks slightly better, and it is now on three lines.

@rust-highfive
Copy link
Collaborator

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.
[00:00:50] sha256:8c1f0882640438d1d5e0c0acc857fedd1a16de0d9ee943660aa40de5c9b49bad
[00:00:50] Attempting with retry: docker build --rm -t rust-ci -f /home/travis/build/rust-lang/rust/src/ci/docker/x86_64-gnu-llvm-3.9/Dockerfile /home/travis/build/rust-lang/rust/src/ci/docker
[00:00:50] Sending build context to Docker daemon  501.2kB
[00:00:50] Step 1/6 : FROM ubuntu:16.04
[00:00:51] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:52] Sending build context to Docker daemon  501.2kB
[00:00:52] Step 1/6 : FROM ubuntu:16.04
[00:00:52] Step 1/6 : FROM ubuntu:16.04
[00:00:52] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:54] Sending build context to Docker daemon  501.2kB
[00:00:54] Step 1/6 : FROM ubuntu:16.04
[00:00:54] Step 1/6 : FROM ubuntu:16.04
[00:00:54] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:00:57] Sending build context to Docker daemon  501.2kB
[00:00:57] Step 1/6 : FROM ubuntu:16.04
[00:00:57] Step 1/6 : FROM ubuntu:16.04
[00:00:58] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:01:02] Sending build context to Docker daemon  501.2kB
[00:01:02] Step 1/6 : FROM ubuntu:16.04
[00:01:02] Step 1/6 : FROM ubuntu:16.04
[00:01:02] Get https://registry-1.docker.io/v2/library/ubuntu/manifests/16.04: received unexpected HTTP status: 503 Service Unavailable
[00:01:02] The command has failed after 5 attempts.

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 1.
travis_time:start:00dbb718
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:049d086a:start=1529879663256119291,finish=1529879663263414160,duration=7294869
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:15b98be1
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:3111c896
$ dmesg | grep -i kill

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 @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Jun 27, 2018

@anirudhb: 🔑 Insufficient privileges: not in try users

1 similar comment
@bors
Copy link
Contributor

bors commented Jun 27, 2018

@anirudhb: 🔑 Insufficient privileges: not in try users

@Mark-Simulacrum
Copy link
Member

I've restarted the travis build manually.

@anirudhb
Copy link
Contributor Author

Thank you, I think it was an unrelated error to the documentation change.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of 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.

[00:05:07] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:05:07] tidy error: /checkout/src/libcore/slice/mod.rs:1544: trailing whitespace
[00:05:07] tidy error: /checkout/src/libcore/slice/mod.rs:1613: trailing whitespace
[00:05:09] some tidy checks failed
[00:05:09] 
[00:05:09] 
[00:05:09] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:09] 
[00:05:09] 
[00:05:09] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:09] Build completed unsuccessfully in 0:01:53
[00:05:09] Build completed unsuccessfully in 0:01:53
[00:05:09] Makefile:79: recipe for target 'tidy' failed
[00:05:09] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:044bb639
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:0bb6a241:start=1530131408637635592,finish=1530131408644054217,duration=6418625
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0bec1928
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:3ce9b0dc
$ dmesg | grep -i kill

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 @TimNN. (Feature Requests)

@TimNN
Copy link
Contributor

TimNN commented Jul 3, 2018

Ping from triage, @steveklabnik: This PR requires your review!

@pietroalbini pietroalbini added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Jul 9, 2018
@pietroalbini
Copy link
Member

Ping from triage! This PR needs a review, can @steveklabnik or someone else from @rust-lang/docs review this?

@@ -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,
Copy link
Member

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?

Copy link
Contributor Author

@anirudhb anirudhb Jul 9, 2018

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

@steveklabnik
Copy link
Member

steveklabnik commented Jul 9, 2018

@bors: r? @frewsxcv

since he's got it now :)

Sorry about the delay here, @anirudhb ; I was travelling and missed the first ping :(

@GuillaumeGomez
Copy link
Member

I still find the added comments difficult to read/understand.

@@ -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,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@frewsxcv
Copy link
Member

thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 10, 2018

📌 Commit 4b51484 has been approved by frewsxcv

@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 Jul 10, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 11, 2018
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
bors added a commit that referenced this pull request Jul 11, 2018
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
@bors bors merged commit 4b51484 into rust-lang:master Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why do copy_from_slice and clone_from_slice require equal size?
9 participants