Skip to content

Commit 3c286d5

Browse files
committed
Make os/windows default to deny unsafe in unsafe
1 parent d96ed86 commit 3c286d5

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

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

+18-10
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ fn stdio_handle(raw: RawHandle) -> RawHandle {
159159
impl FromRawHandle for fs::File {
160160
#[inline]
161161
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
162-
let handle = handle as sys::c::HANDLE;
163-
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
164-
OwnedHandle::from_raw_handle(handle),
165-
)))
162+
unsafe {
163+
let handle = handle as sys::c::HANDLE;
164+
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
165+
OwnedHandle::from_raw_handle(handle),
166+
)))
167+
}
166168
}
167169
}
168170

@@ -260,24 +262,30 @@ impl AsRawSocket for net::UdpSocket {
260262
impl FromRawSocket for net::TcpStream {
261263
#[inline]
262264
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream {
263-
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
264-
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
265+
unsafe {
266+
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
267+
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
268+
}
265269
}
266270
}
267271
#[stable(feature = "from_raw_os", since = "1.1.0")]
268272
impl FromRawSocket for net::TcpListener {
269273
#[inline]
270274
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener {
271-
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
272-
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
275+
unsafe {
276+
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
277+
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
278+
}
273279
}
274280
}
275281
#[stable(feature = "from_raw_os", since = "1.1.0")]
276282
impl FromRawSocket for net::UdpSocket {
277283
#[inline]
278284
unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket {
279-
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
280-
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
285+
unsafe {
286+
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
287+
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
288+
}
281289
}
282290
}
283291

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl BorrowedSocket<'_> {
7676
#[stable(feature = "io_safety", since = "1.63.0")]
7777
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
7878
assert!(socket != sys::c::INVALID_SOCKET as RawSocket);
79-
Self { socket, _phantom: PhantomData }
79+
unsafe { Self { socket, _phantom: PhantomData } }
8080
}
8181
}
8282

@@ -201,8 +201,10 @@ impl IntoRawSocket for OwnedSocket {
201201
impl FromRawSocket for OwnedSocket {
202202
#[inline]
203203
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
204-
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
205-
Self { socket }
204+
unsafe {
205+
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
206+
Self { socket }
207+
}
206208
}
207209
}
208210

std/src/os/windows/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
#![stable(feature = "rust1", since = "1.0.0")]
2626
#![doc(cfg(windows))]
27+
#![deny(unsafe_op_in_unsafe_fn)]
2728

2829
pub mod ffi;
2930
pub mod fs;

std/src/os/windows/process.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1616
#[stable(feature = "process_extensions", since = "1.2.0")]
1717
impl FromRawHandle for process::Stdio {
1818
unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio {
19-
let handle = sys::handle::Handle::from_raw_handle(handle as *mut _);
19+
let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) };
2020
let io = sys::process::Stdio::Handle(handle);
2121
process::Stdio::from_inner(io)
2222
}
@@ -407,7 +407,7 @@ impl CommandExt for process::Command {
407407
attribute: usize,
408408
value: T,
409409
) -> &mut process::Command {
410-
self.as_inner_mut().raw_attribute(attribute, value);
410+
unsafe { self.as_inner_mut().raw_attribute(attribute, value) };
411411
self
412412
}
413413
}

0 commit comments

Comments
 (0)