Skip to content

Commit b2b225e

Browse files
committed
sync the various FromRawFd trait docs, and remove 'valid'
1 parent a473e95 commit b2b225e

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

library/std/src/os/fd/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub trait FromRawFd {
8585
/// # Safety
8686
///
8787
/// The `fd` passed in must be an [owned file descriptor][io-safety];
88-
/// in particular, it must be valid and open.
88+
/// in particular, it must be open.
8989
///
9090
/// [io-safety]: io#io-safety
9191
///

library/std/src/os/fortanix_sgx/io.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ pub trait FromRawFd {
3131
/// Constructs a new instance of `Self` from the given raw file
3232
/// descriptor and metadata.
3333
///
34-
/// This function **consumes [ownership][io-safety]** of the specified file
35-
/// descriptor. The returned object will take responsibility for closing
36-
/// it when the object goes out of scope.
34+
/// This function is typically used to **consume ownership** of the
35+
/// specified file descriptor. When used in this way, the returned object
36+
/// will take responsibility for closing it when the object goes out of
37+
/// scope.
3738
///
38-
/// [io-safety]: crate::io#io-safety
39+
/// However, consuming ownership is not strictly required. Use a
40+
/// [`From<OwnedFd>::from`] implementation for an API which strictly
41+
/// consumes ownership.
3942
///
40-
/// This function is also unsafe as the primitives currently returned
41-
/// have the contract that they are the sole owner of the file
42-
/// descriptor they are wrapping. Usage of this function could
43-
/// accidentally allow violating this contract which can cause memory
44-
/// unsafety in code that relies on it being true.
43+
/// # Safety
44+
///
45+
/// The `fd` passed in must be an [owned file descriptor][io-safety];
46+
/// in particular, it must be open.
47+
// FIXME: say something about `metadata`.
48+
///
49+
/// [io-safety]: io#io-safety
4550
#[unstable(feature = "sgx_platform", issue = "56975")]
4651
unsafe fn from_raw_fd(fd: RawFd, metadata: Self::Metadata) -> Self;
4752
}

library/std/src/os/solid/io.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@ pub trait FromRawFd {
2727
/// Constructs a new instance of `Self` from the given raw file
2828
/// descriptor.
2929
///
30-
/// This function **consumes [ownership][io-safety]** of the specified file
31-
/// descriptor. The returned object will take responsibility for closing
32-
/// it when the object goes out of scope.
30+
/// This function is typically used to **consume ownership** of the
31+
/// specified file descriptor. When used in this way, the returned object
32+
/// will take responsibility for closing it when the object goes out of
33+
/// scope.
3334
///
34-
/// [io-safety]: crate::io#io-safety
35+
/// However, consuming ownership is not strictly required. Use a
36+
/// [`From<OwnedFd>::from`] implementation for an API which strictly
37+
/// consumes ownership.
3538
///
36-
/// This function is also unsafe as the primitives currently returned
37-
/// have the contract that they are the sole owner of the file
38-
/// descriptor they are wrapping. Usage of this function could
39-
/// accidentally allow violating this contract which can cause memory
40-
/// unsafety in code that relies on it being true.
39+
/// # Safety
40+
///
41+
/// The `fd` passed in must be an [owned file descriptor][io-safety];
42+
/// in particular, it must be open.
43+
///
44+
/// [io-safety]: io#io-safety
4145
unsafe fn from_raw_fd(fd: RawFd) -> Self;
4246
}
4347

library/std/src/os/windows/io/raw.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub trait FromRawHandle {
6262
/// # Safety
6363
///
6464
/// The `handle` passed in must:
65-
/// - be a valid an open handle,
65+
/// - be an [owned handle][io-safety]; in particular, it must be open.
6666
/// - be a handle for a resource that may be freed via [`CloseHandle`]
6767
/// (as opposed to `RegCloseKey` or other close functions).
6868
///
@@ -71,6 +71,7 @@ pub trait FromRawHandle {
7171
///
7272
/// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
7373
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
74+
/// [io-safety]: io#io-safety
7475
#[stable(feature = "from_raw_os", since = "1.1.0")]
7576
unsafe fn from_raw_handle(handle: RawHandle) -> Self;
7677
}
@@ -207,10 +208,11 @@ pub trait FromRawSocket {
207208
/// # Safety
208209
///
209210
/// The `socket` passed in must:
210-
/// - be a valid an open socket,
211+
/// - be an [owned socket][io-safety]; in particular, it must be open.
211212
/// - be a socket that may be freed via [`closesocket`].
212213
///
213214
/// [`closesocket`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket
215+
/// [io-safety]: io#io-safety
214216
#[stable(feature = "from_raw_os", since = "1.1.0")]
215217
unsafe fn from_raw_socket(sock: RawSocket) -> Self;
216218
}

0 commit comments

Comments
 (0)