Skip to content

Docs enhancement: misleading try_clone docs #77520

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

Open
rbtcollins opened this issue Oct 4, 2020 · 2 comments
Open

Docs enhancement: misleading try_clone docs #77520

rbtcollins opened this issue Oct 4, 2020 · 2 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@rbtcollins
Copy link
Contributor

rbtcollins commented Oct 4, 2020

try_clone says it "Creates a new File instance that shares the same underlying file handle as the existing File instance."

However, #45536 notes that it calls DuplicateHandle and fcntl F_DUPFD_CLOEXEC on Windows and other OSes respectively. Those calls create new handles, which point to the same operating system descriptor (file, socket etc).

The distinction is potentially important: file system behaviours that can cause IO latency may be hooked in on syscalls like close() - we've spent considerable time in rustup dealing with virus scanners and NFS for two examples.

I think the documentation should at a minimum say 'new operating system handle cloned from the existing one', or some such. Ideally it would, like other calls do, just say what calls are used: this is clear and unambiguous, and would also solve the problem raised in bug 45536 about documentation about when it may fail by letting folk go and read the underlying syscall documentation.

Meta

This is present still in git. https://doc.rust-lang.org/src/std/fs.rs.html#548

@rbtcollins rbtcollins added the C-bug Category: This is a bug. label Oct 4, 2020
@jyn514 jyn514 added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Oct 4, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 4, 2020

Perma-link:

/// Creates a new `File` instance that shares the same underlying file handle

@jyn514 jyn514 added A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 4, 2020
@hkBst
Copy link
Member

hkBst commented Feb 1, 2025

Still present and the example also seems meh.

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 A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants