diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2021-07-27 17:08:27 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2021-08-19 12:02:39 -0700 |
| commit | 0cb69dec57f9ad279d7ceefad26cb0d2e16107bc (patch) | |
| tree | 757494d77a16b17e5424f62611e15dd7de705dcf /library/std/src/os/windows | |
| parent | 45b5de3376bdfdd04222add3f42e39f933984993 (diff) | |
Rename `OwnedFd`'s private field to match it's debug output.
Diffstat (limited to 'library/std/src/os/windows')
| -rw-r--r-- | library/std/src/os/windows/io/handle.rs | 68 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/socket.rs | 35 |
2 files changed, 52 insertions, 51 deletions
diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index e9128684354..5d250520685 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -30,7 +30,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; #[repr(transparent)] #[unstable(feature = "io_safety", issue = "87074")] pub struct BorrowedHandle<'handle> { - raw: NonNull<c_void>, + handle: NonNull<c_void>, _phantom: PhantomData<&'handle OwnedHandle>, } @@ -58,7 +58,7 @@ pub struct BorrowedHandle<'handle> { #[repr(transparent)] #[unstable(feature = "io_safety", issue = "87074")] pub struct OwnedHandle { - raw: NonNull<c_void>, + handle: NonNull<c_void>, } /// Similar to `Option<OwnedHandle>`, but intended for use in FFI interfaces @@ -78,7 +78,7 @@ pub struct OwnedHandle { #[repr(transparent)] #[unstable(feature = "io_safety", issue = "87074")] pub struct OptionFileHandle { - raw: RawHandle, + handle: RawHandle, } // The Windows [`HANDLE`] type may be transferred across and shared between @@ -98,13 +98,13 @@ impl BorrowedHandle<'_> { /// /// # Safety /// - /// The resource pointed to by `raw` must remain open for the duration of - /// the returned `BorrowedHandle`, and it must not be null. + /// The resource pointed to by `handle` must remain open for the duration + /// of the returned `BorrowedHandle`, and it must not be null. #[inline] #[unstable(feature = "io_safety", issue = "87074")] - pub unsafe fn borrow_raw_handle(raw: RawHandle) -> Self { - assert!(!raw.is_null()); - Self { raw: NonNull::new_unchecked(raw), _phantom: PhantomData } + pub unsafe fn borrow_raw_handle(handle: RawHandle) -> Self { + assert!(!handle.is_null()); + Self { handle: NonNull::new_unchecked(handle), _phantom: PhantomData } } } @@ -113,7 +113,7 @@ impl OptionFileHandle { #[inline] #[unstable(feature = "io_safety", issue = "87074")] pub const fn none() -> Self { - Self { raw: c::INVALID_HANDLE_VALUE } + Self { handle: c::INVALID_HANDLE_VALUE } } } @@ -122,19 +122,19 @@ impl TryFrom<OptionFileHandle> for OwnedHandle { #[inline] fn try_from(option: OptionFileHandle) -> Result<Self, ()> { - let raw = option.raw; + let handle = option.handle; forget(option); - if let Some(non_null) = NonNull::new(raw) { + if let Some(non_null) = NonNull::new(handle) { if non_null.as_ptr() != c::INVALID_HANDLE_VALUE { - Ok(Self { raw: non_null }) + Ok(Self { handle: non_null }) } else { Err(()) } } else { // In theory, we ought to be able to assume that the pointer here - // is never null, change `option.raw` to `NonNull`, and obviate the - // the panic path here. Unfortunately, Win32 documentation doesn't - // explicitly guarantee this anywhere. + // is never null, change `option.handle` to `NonNull`, and obviate + // the the panic path here. Unfortunately, Win32 documentation + // doesn't explicitly guarantee this anywhere. // // APIs like [`CreateFileW`] itself have `HANDLE` arguments where a // null handle indicates an absent value, which wouldn't work if @@ -150,32 +150,32 @@ impl TryFrom<OptionFileHandle> for OwnedHandle { impl From<OwnedHandle> for OptionFileHandle { #[inline] fn from(owned: OwnedHandle) -> Self { - let raw = owned.raw; + let handle = owned.handle; forget(owned); - Self { raw: raw.as_ptr() } + Self { handle: handle.as_ptr() } } } impl AsRawHandle for BorrowedHandle<'_> { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.raw.as_ptr() + self.handle.as_ptr() } } impl AsRawHandle for OwnedHandle { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.raw.as_ptr() + self.handle.as_ptr() } } impl IntoRawHandle for OwnedHandle { #[inline] fn into_raw_handle(self) -> RawHandle { - let raw = self.raw.as_ptr(); + let handle = self.handle.as_ptr(); forget(self); - raw + handle } } @@ -184,7 +184,7 @@ impl FromRawHandle for OwnedHandle { /// /// # Safety /// - /// The resource pointed to by `raw` must be open and suitable for + /// The resource pointed to by `handle` must be open and suitable for /// assuming ownership. The resource must not require any cleanup other /// than `CloseHandle`. /// @@ -193,9 +193,9 @@ impl FromRawHandle for OwnedHandle { /// /// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey #[inline] - unsafe fn from_raw_handle(raw: RawHandle) -> Self { - assert!(!raw.is_null()); - Self { raw: NonNull::new_unchecked(raw) } + unsafe fn from_raw_handle(handle: RawHandle) -> Self { + assert!(!handle.is_null()); + Self { handle: NonNull::new_unchecked(handle) } } } @@ -204,16 +204,16 @@ impl FromRawHandle for OptionFileHandle { /// /// # Safety /// - /// The resource pointed to by `raw` must be either open and otherwise + /// The resource pointed to by `handle` must be either open and otherwise /// unowned, or equal to `INVALID_HANDLE_VALUE``. Note that not all Windows /// APIs use `INVALID_HANDLE_VALUE` for errors; see [here] for the full /// story. /// /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 #[inline] - unsafe fn from_raw_handle(raw: RawHandle) -> Self { - assert!(!raw.is_null()); - Self { raw } + unsafe fn from_raw_handle(handle: RawHandle) -> Self { + assert!(!handle.is_null()); + Self { handle } } } @@ -221,7 +221,7 @@ impl Drop for OwnedHandle { #[inline] fn drop(&mut self) { unsafe { - let _ = c::CloseHandle(self.raw.as_ptr()); + let _ = c::CloseHandle(self.handle.as_ptr()); } } } @@ -230,26 +230,26 @@ impl Drop for OptionFileHandle { #[inline] fn drop(&mut self) { unsafe { - let _ = c::CloseHandle(self.raw); + let _ = c::CloseHandle(self.handle); } } } impl fmt::Debug for BorrowedHandle<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("BorrowedHandle").field("handle", &self.raw).finish() + f.debug_struct("BorrowedHandle").field("handle", &self.handle).finish() } } impl fmt::Debug for OwnedHandle { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("OwnedHandle").field("handle", &self.raw).finish() + f.debug_struct("OwnedHandle").field("handle", &self.handle).finish() } } impl fmt::Debug for OptionFileHandle { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("OptionFileHandle").field("handle", &self.raw).finish() + f.debug_struct("OptionFileHandle").field("handle", &self.handle).finish() } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 28695042a2b..fd89f4cc60c 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -28,7 +28,7 @@ use crate::sys::c; )] #[unstable(feature = "io_safety", issue = "87074")] pub struct BorrowedSocket<'socket> { - raw: RawSocket, + socket: RawSocket, _phantom: PhantomData<&'socket OwnedSocket>, } @@ -50,7 +50,7 @@ pub struct BorrowedSocket<'socket> { )] #[unstable(feature = "io_safety", issue = "87074")] pub struct OwnedSocket { - raw: RawSocket, + socket: RawSocket, } impl BorrowedSocket<'_> { @@ -63,32 +63,32 @@ impl BorrowedSocket<'_> { /// `INVALID_SOCKET`. #[inline] #[unstable(feature = "io_safety", issue = "87074")] - pub unsafe fn borrow_raw_socket(raw: RawSocket) -> Self { - debug_assert_ne!(raw, c::INVALID_SOCKET as RawSocket); - Self { raw, _phantom: PhantomData } + pub unsafe fn borrow_raw_socket(socket: RawSocket) -> Self { + debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket); + Self { socket, _phantom: PhantomData } } } impl AsRawSocket for BorrowedSocket<'_> { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.raw + self.socket } } impl AsRawSocket for OwnedSocket { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.raw + self.socket } } impl IntoRawSocket for OwnedSocket { #[inline] fn into_raw_socket(self) -> RawSocket { - let raw = self.raw; + let socket = self.socket; forget(self); - raw + socket } } @@ -97,12 +97,13 @@ impl FromRawSocket for OwnedSocket { /// /// # Safety /// - /// The resource pointed to by `raw` must be open and suitable for assuming - /// ownership. The resource must not require cleanup other than `closesocket`. + /// The resource pointed to by `socket` must be open and suitable for + /// assuming ownership. The resource must not require cleanup other than + /// `closesocket`. #[inline] - unsafe fn from_raw_socket(raw: RawSocket) -> Self { - debug_assert_ne!(raw, c::INVALID_SOCKET as RawSocket); - Self { raw } + unsafe fn from_raw_socket(socket: RawSocket) -> Self { + debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket); + Self { socket } } } @@ -110,20 +111,20 @@ impl Drop for OwnedSocket { #[inline] fn drop(&mut self) { unsafe { - let _ = c::closesocket(self.raw); + let _ = c::closesocket(self.socket); } } } impl fmt::Debug for BorrowedSocket<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("BorrowedSocket").field("socket", &self.raw).finish() + f.debug_struct("BorrowedSocket").field("socket", &self.socket).finish() } } impl fmt::Debug for OwnedSocket { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("OwnedSocket").field("socket", &self.raw).finish() + f.debug_struct("OwnedSocket").field("socket", &self.socket).finish() } } |
