-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
BorrowedFd::to_owned() gives you another BorrowedFd #88564
Copy link
Copy link
Closed
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Firstly, I should say that I really like the basic ideas in RFC3128 (#87074) . I'm reporting a wrinkle which may or may not be soluble.
This program:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d51ddfa5a390e4d1b8f8bf81af8b0d73
Prints:
A naive reader might have thought it would print:
But of course converting a borrowed to an owned fd is fallible. And there is no
TryToOwned. This no-opto_owned()exists becauseBorrowedFdisCopyand thereforeCloneand eveyrhingClonehas a no-opToOwned.The ideal fix from a type system and traits point of view (other than going back in time and abolishing the blanket
ToOwned for Clone) would be forBorrowedFdto somehow be a reference type. But it would have to actually be represented as an integer.pub struct BorrowableFdValue { x:() }and transmutingc_intviausizeto&BorrowableFdValueand back would solve this but that is really quite stomach-churning (and the result can't be used in ffi the way the existingBorrowedFdcan).Maybe the answer is to simply document this quirk. We should probably provide
impl TryFrom<OwnedFd> from BorrowedFdat the very least, and of courseOwnedFd::try_clone().