Skip to content

Commit cba1407

Browse files
committed
Auto merge of #111401 - ChrisDenton:no-windows-allowed, r=workingjubilee
Don't force include Windows goop when documenting Why do we need to include all the windows bits on non-windows platforms? Let's try not doing that. Possible alternative to #111394, if it works.
2 parents 25444e5 + d076607 commit cba1407

File tree

4 files changed

+40
-59
lines changed

4 files changed

+40
-59
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::io;
99
use crate::marker::PhantomData;
1010
use crate::mem::forget;
1111
use crate::ptr;
12-
use crate::sys::c;
12+
use crate::sys;
1313
use crate::sys::cvt;
1414
use crate::sys_common::{AsInner, FromInner, IntoInner};
1515

@@ -190,14 +190,14 @@ impl BorrowedHandle<'_> {
190190
/// object as the existing `BorrowedHandle` instance.
191191
#[stable(feature = "io_safety", since = "1.63.0")]
192192
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedHandle> {
193-
self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)
193+
self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS)
194194
}
195195

196196
pub(crate) fn duplicate(
197197
&self,
198-
access: c::DWORD,
198+
access: u32,
199199
inherit: bool,
200-
options: c::DWORD,
200+
options: u32,
201201
) -> io::Result<OwnedHandle> {
202202
let handle = self.as_raw_handle();
203203

@@ -211,14 +211,14 @@ impl BorrowedHandle<'_> {
211211

212212
let mut ret = ptr::null_mut();
213213
cvt(unsafe {
214-
let cur_proc = c::GetCurrentProcess();
215-
c::DuplicateHandle(
214+
let cur_proc = sys::c::GetCurrentProcess();
215+
sys::c::DuplicateHandle(
216216
cur_proc,
217217
handle,
218218
cur_proc,
219219
&mut ret,
220220
access,
221-
inherit as c::BOOL,
221+
inherit as sys::c::BOOL,
222222
options,
223223
)
224224
})?;
@@ -233,7 +233,7 @@ impl TryFrom<HandleOrInvalid> for OwnedHandle {
233233
#[inline]
234234
fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError> {
235235
let owned_handle = handle_or_invalid.0;
236-
if owned_handle.handle == c::INVALID_HANDLE_VALUE {
236+
if owned_handle.handle == sys::c::INVALID_HANDLE_VALUE {
237237
// Don't call `CloseHandle`; it'd be harmless, except that it could
238238
// overwrite the `GetLastError` error.
239239
forget(owned_handle);
@@ -365,7 +365,7 @@ impl Drop for OwnedHandle {
365365
#[inline]
366366
fn drop(&mut self) {
367367
unsafe {
368-
let _ = c::CloseHandle(self.handle);
368+
let _ = sys::c::CloseHandle(self.handle);
369369
}
370370
}
371371
}

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::os::windows::io::{OwnedHandle, OwnedSocket};
1111
use crate::os::windows::raw;
1212
use crate::ptr;
1313
use crate::sys;
14-
use crate::sys::c;
1514
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
1615

1716
/// Raw HANDLEs.
@@ -104,42 +103,42 @@ impl AsRawHandle for fs::File {
104103
#[stable(feature = "asraw_stdio", since = "1.21.0")]
105104
impl AsRawHandle for io::Stdin {
106105
fn as_raw_handle(&self) -> RawHandle {
107-
stdio_handle(unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle })
106+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_INPUT_HANDLE) as RawHandle })
108107
}
109108
}
110109

111110
#[stable(feature = "asraw_stdio", since = "1.21.0")]
112111
impl AsRawHandle for io::Stdout {
113112
fn as_raw_handle(&self) -> RawHandle {
114-
stdio_handle(unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle })
113+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_OUTPUT_HANDLE) as RawHandle })
115114
}
116115
}
117116

118117
#[stable(feature = "asraw_stdio", since = "1.21.0")]
119118
impl AsRawHandle for io::Stderr {
120119
fn as_raw_handle(&self) -> RawHandle {
121-
stdio_handle(unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle })
120+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_ERROR_HANDLE) as RawHandle })
122121
}
123122
}
124123

125124
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
126125
impl<'a> AsRawHandle for io::StdinLock<'a> {
127126
fn as_raw_handle(&self) -> RawHandle {
128-
stdio_handle(unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle })
127+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_INPUT_HANDLE) as RawHandle })
129128
}
130129
}
131130

132131
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
133132
impl<'a> AsRawHandle for io::StdoutLock<'a> {
134133
fn as_raw_handle(&self) -> RawHandle {
135-
stdio_handle(unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle })
134+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_OUTPUT_HANDLE) as RawHandle })
136135
}
137136
}
138137

139138
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
140139
impl<'a> AsRawHandle for io::StderrLock<'a> {
141140
fn as_raw_handle(&self) -> RawHandle {
142-
stdio_handle(unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle })
141+
stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_ERROR_HANDLE) as RawHandle })
143142
}
144143
}
145144

@@ -152,14 +151,14 @@ fn stdio_handle(raw: RawHandle) -> RawHandle {
152151
// console. In that case, return null to the user, which is consistent
153152
// with what they'd get in the parent, and which avoids the problem that
154153
// `INVALID_HANDLE_VALUE` aliases the current process handle.
155-
if raw == c::INVALID_HANDLE_VALUE { ptr::null_mut() } else { raw }
154+
if raw == sys::c::INVALID_HANDLE_VALUE { ptr::null_mut() } else { raw }
156155
}
157156

158157
#[stable(feature = "from_raw_os", since = "1.1.0")]
159158
impl FromRawHandle for fs::File {
160159
#[inline]
161160
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
162-
let handle = handle as c::HANDLE;
161+
let handle = handle as sys::c::HANDLE;
163162
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
164163
OwnedHandle::from_raw_handle(handle),
165164
)))

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

+23-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::marker::PhantomData;
99
use crate::mem;
1010
use crate::mem::forget;
1111
use crate::sys;
12-
use crate::sys::c;
1312
#[cfg(not(target_vendor = "uwp"))]
1413
use crate::sys::cvt;
1514

@@ -76,7 +75,7 @@ impl BorrowedSocket<'_> {
7675
#[rustc_const_stable(feature = "io_safety", since = "1.63.0")]
7776
#[stable(feature = "io_safety", since = "1.63.0")]
7877
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
79-
assert!(socket != c::INVALID_SOCKET as RawSocket);
78+
assert!(socket != sys::c::INVALID_SOCKET as RawSocket);
8079
Self { socket, _phantom: PhantomData }
8180
}
8281
}
@@ -94,7 +93,11 @@ impl OwnedSocket {
9493
#[cfg(not(target_vendor = "uwp"))]
9594
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
9695
cvt(unsafe {
97-
c::SetHandleInformation(self.as_raw_socket() as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0)
96+
sys::c::SetHandleInformation(
97+
self.as_raw_socket() as sys::c::HANDLE,
98+
sys::c::HANDLE_FLAG_INHERIT,
99+
0,
100+
)
98101
})
99102
.map(drop)
100103
}
@@ -110,43 +113,47 @@ impl BorrowedSocket<'_> {
110113
/// object as the existing `BorrowedSocket` instance.
111114
#[stable(feature = "io_safety", since = "1.63.0")]
112115
pub fn try_clone_to_owned(&self) -> io::Result<OwnedSocket> {
113-
let mut info = unsafe { mem::zeroed::<c::WSAPROTOCOL_INFOW>() };
116+
let mut info = unsafe { mem::zeroed::<sys::c::WSAPROTOCOL_INFOW>() };
114117
let result = unsafe {
115-
c::WSADuplicateSocketW(self.as_raw_socket(), c::GetCurrentProcessId(), &mut info)
118+
sys::c::WSADuplicateSocketW(
119+
self.as_raw_socket(),
120+
sys::c::GetCurrentProcessId(),
121+
&mut info,
122+
)
116123
};
117124
sys::net::cvt(result)?;
118125
let socket = unsafe {
119-
c::WSASocketW(
126+
sys::c::WSASocketW(
120127
info.iAddressFamily,
121128
info.iSocketType,
122129
info.iProtocol,
123130
&mut info,
124131
0,
125-
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT,
132+
sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT,
126133
)
127134
};
128135

129-
if socket != c::INVALID_SOCKET {
136+
if socket != sys::c::INVALID_SOCKET {
130137
unsafe { Ok(OwnedSocket::from_raw_socket(socket)) }
131138
} else {
132-
let error = unsafe { c::WSAGetLastError() };
139+
let error = unsafe { sys::c::WSAGetLastError() };
133140

134-
if error != c::WSAEPROTOTYPE && error != c::WSAEINVAL {
141+
if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL {
135142
return Err(io::Error::from_raw_os_error(error));
136143
}
137144

138145
let socket = unsafe {
139-
c::WSASocketW(
146+
sys::c::WSASocketW(
140147
info.iAddressFamily,
141148
info.iSocketType,
142149
info.iProtocol,
143150
&mut info,
144151
0,
145-
c::WSA_FLAG_OVERLAPPED,
152+
sys::c::WSA_FLAG_OVERLAPPED,
146153
)
147154
};
148155

149-
if socket == c::INVALID_SOCKET {
156+
if socket == sys::c::INVALID_SOCKET {
150157
return Err(last_error());
151158
}
152159

@@ -161,7 +168,7 @@ impl BorrowedSocket<'_> {
161168

162169
/// Returns the last error from the Windows socket interface.
163170
fn last_error() -> io::Error {
164-
io::Error::from_raw_os_error(unsafe { c::WSAGetLastError() })
171+
io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() })
165172
}
166173

167174
#[stable(feature = "io_safety", since = "1.63.0")]
@@ -194,7 +201,7 @@ impl IntoRawSocket for OwnedSocket {
194201
impl FromRawSocket for OwnedSocket {
195202
#[inline]
196203
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
197-
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);
204+
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
198205
Self { socket }
199206
}
200207
}
@@ -204,7 +211,7 @@ impl Drop for OwnedSocket {
204211
#[inline]
205212
fn drop(&mut self) {
206213
unsafe {
207-
let _ = c::closesocket(self.socket);
214+
let _ = sys::c::closesocket(self.socket);
208215
}
209216
}
210217
}

library/std/src/sys/mod.rs

-25
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,6 @@ cfg_if::cfg_if! {
5252
}
5353
}
5454

55-
// Import essential modules from platforms used in `std::os` when documenting.
56-
//
57-
// Note that on some platforms those modules don't compile
58-
// (missing things in `libc` which is empty), so they are not included in `std::os` and can be
59-
// omitted here as well.
60-
61-
#[cfg(doc)]
62-
#[cfg(not(any(
63-
all(target_arch = "wasm32", not(target_os = "wasi")),
64-
all(target_vendor = "fortanix", target_env = "sgx")
65-
)))]
66-
cfg_if::cfg_if! {
67-
if #[cfg(not(windows))] {
68-
// On non-Windows platforms (aka linux/osx/etc) pull in a "minimal"
69-
// amount of windows goop which ends up compiling
70-
71-
#[macro_use]
72-
#[path = "windows/compat.rs"]
73-
pub mod compat;
74-
75-
#[path = "windows/c.rs"]
76-
pub mod c;
77-
}
78-
}
79-
8055
cfg_if::cfg_if! {
8156
// Fuchsia components default to full backtrace.
8257
if #[cfg(target_os = "fuchsia")] {

0 commit comments

Comments
 (0)