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

Add TryClone trait #56994

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@clarcharr
Copy link
Contributor

clarcharr commented Dec 19, 2018

Presumably, this will require an RFC to properly stabilise, but this seems simple enough to warrant opening a PR. I doubt the API would be substantially different from the one I've provided, as it's very simple.

Basically, there are a few things in the standard library that have a try_clone method, and it seems very reasonable to add a TryClone trait as an analogue to TryFrom and TryInto. I've personally run into a few cases where it'd be useful to have a trait like this, although again, it's up to others on whether this is useful.

A few unanswered questions:

  • Would #[derive(TryClone)] even make sense? What would the error type be?
  • Should there be a try_clone_from? What would the behaviour be if the clone fails?
  • Once this trait is added, should the inherent methods be soft-deprecated?
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Dec 19, 2018

r? @Kimundi

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

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 19, 2018

The job x86_64-gnu-llvm-6.0 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.
travis_time:end:05b1f6d6:start=1545253659604570469,finish=1545253660711494110,duration=1106923641
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:03:35]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:03:36] error[E0405]: cannot find trait `TryClone` in this scope
[00:03:36]    --> src/libstd/fs.rs:586:6
[00:03:36]     |
[00:03:36] 586 | impl TryClone for File {
[00:03:36] help: possible candidate is found in another module, you can import it into scope
[00:03:36]     |
[00:03:36] 20  | use core::clone::TryClone;
[00:03:36]     |
[00:03:36]     |
[00:03:36] 
[00:03:36] error[E0405]: cannot find trait `TryClone` in this scope
[00:03:36]    --> src/libstd/net/tcp.rs:579:6
[00:03:36]     |
[00:03:36] 579 | impl TryClone for TcpStream {
[00:03:36] help: possible candidate is found in another module, you can import it into scope
[00:03:36]     |
[00:03:36] 11  | use core::clone::TryClone;
[00:03:36]     |
[00:03:36]     |
[00:03:36] 
[00:03:36] error[E0405]: cannot find trait `TryClone` in this scope
[00:03:36]    --> src/libstd/net/tcp.rs:899:6
[00:03:36]     |
[00:03:36] 899 | impl TryClone for TcpListener {
[00:03:36] help: possible candidate is found in another module, you can import it into scope
[00:03:36]     |
[00:03:36] 11  | use core::clone::TryClone;
[00:03:36]     |
[00:03:36]     |
[00:03:36] 
[00:03:36] error[E0405]: cannot find trait `TryClone` in this scope
[00:03:36]    --> src/libstd/net/udp.rs:801:6
[00:03:36]     |
[00:03:36] 801 | impl TryClone for UdpSocket {
[00:03:36] help: possible candidate is found in another module, you can import it into scope
[00:03:36]     |
[00:03:36] 11  | use core::clone::TryClone;
[00:03:36]     |
---
[00:03:36] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:03:36] expected success, got: exit code: 101
[00:03:36] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:03:36] Build completed unsuccessfully in 0:00:40
[00:03:36] make: *** [all] Error 1
[00:03:36] Makefile:28: recipe for target 'all' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:031103a8
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Dec 19 21:11:26 UTC 2018
---
travis_time:end:0dce90a8:start=1545253886906345854,finish=1545253886912995596,duration=6649742
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1597aa03
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:061e49ae
travis_time:start:061e49ae
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:02dcfad0
$ 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)

@clarcharr clarcharr force-pushed the clarcharr:try_clone branch from e7d5d53 to 01252c1 Dec 19, 2018

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 19, 2018

The job x86_64-gnu-llvm-6.0 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.
travis_time:end:20857e0e:start=1545254431050877912,finish=1545254432291275494,duration=1240397582
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/fs.rs:589:5
[00:04:34]     |
[00:04:34] 589 | /     fn try_clone(&self) -> io::Result<File> {
[00:04:34] 590 | |         File::try_clone(self)
[00:04:34]     | |_____^
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/fs.rs:587:6
[00:04:34]     |
[00:04:34] 587 | impl TryClone for File {
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
---
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/tcp.rs:582:5
[00:04:34]     |
[00:04:34] 582 | /     fn try_clone(&self) -> io::Result<TcpStream> {
[00:04:34] 583 | |         TcpStream::try_clone(self)
[00:04:34]     | |_____^
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/tcp.rs:580:6
[00:04:34]     |
[00:04:34] 580 | impl TryClone for TcpStream {
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
---
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/tcp.rs:902:5
[00:04:34]     |
[00:04:34] 902 | /     fn try_clone(&self) -> io::Result<TcpListener> {
[00:04:34] 903 | |         TcpListener::try_clone(self)
[00:04:34]     | |_____^
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/tcp.rs:900:6
[00:04:34]     |
[00:04:34] 900 | impl TryClone for TcpListener {
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
---
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/udp.rs:804:5
[00:04:34]     |
[00:04:34] 804 | /     fn try_clone(&self) -> io::Result<UdpSocket> {
[00:04:34] 805 | |         UdpSocket::try_clone(self)
[00:04:34]     | |_____^
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
[00:04:34] 
[00:04:34] error[E0658]: use of unstable library feature 'try_clone'
[00:04:34]    --> src/libstd/net/udp.rs:802:6
[00:04:34]     |
[00:04:34] 802 | impl TryClone for UdpSocket {
[00:04:34]     |
[00:04:34]     = help: add #![feature(try_clone)] to the crate attributes to enable
[00:04:34] 
llvm/test/MC/X86
---
10956 ./src/llvm/test/MC/Disassembler/AMDGPU
10820 ./src/tools/lldb/unittests
10508 ./src/llvm/test/MC/AMDGPU
10332 ./src/tools/clang/include
10140 ./src/tools/lldb/packages/Python/lldbsuite/test/functionalities/postmortem
travis_fold:end:after_failure.1
travis_fold:start:after_failure.2
travis_time:start:22629b40
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
---
travis_time:end:08fb57a0:start=1545254716931794425,finish=1545254716938512626,duration=6718201
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:28f7a010
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|ob

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)

@clarcharr clarcharr force-pushed the clarcharr:try_clone branch from 01252c1 to 0f9dedd Dec 19, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 26, 2018

☔️ The latest upstream changes (presumably #57108) made this pull request unmergeable. Please resolve the merge conflicts.

@clarcharr clarcharr force-pushed the clarcharr:try_clone branch from 0f9dedd to 641c9cd Dec 26, 2018

@clarcharr clarcharr force-pushed the clarcharr:try_clone branch from 641c9cd to 6ae87e0 Jan 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment