mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Make os/windows default to deny unsafe in unsafe
This commit is contained in:
parent
2402e84e78
commit
3411a025d5
@ -159,10 +159,12 @@ fn stdio_handle(raw: RawHandle) -> RawHandle {
|
||||
impl FromRawHandle for fs::File {
|
||||
#[inline]
|
||||
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
|
||||
let handle = handle as sys::c::HANDLE;
|
||||
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
|
||||
OwnedHandle::from_raw_handle(handle),
|
||||
)))
|
||||
unsafe {
|
||||
let handle = handle as sys::c::HANDLE;
|
||||
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
|
||||
OwnedHandle::from_raw_handle(handle),
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,24 +262,30 @@ impl AsRawSocket for net::UdpSocket {
|
||||
impl FromRawSocket for net::TcpStream {
|
||||
#[inline]
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
|
||||
unsafe {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawSocket for net::TcpListener {
|
||||
#[inline]
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
|
||||
unsafe {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawSocket for net::UdpSocket {
|
||||
#[inline]
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
|
||||
unsafe {
|
||||
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
|
||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ impl BorrowedSocket<'_> {
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
|
||||
assert!(socket != sys::c::INVALID_SOCKET as RawSocket);
|
||||
Self { socket, _phantom: PhantomData }
|
||||
unsafe { Self { socket, _phantom: PhantomData } }
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,8 +201,10 @@ impl IntoRawSocket for OwnedSocket {
|
||||
impl FromRawSocket for OwnedSocket {
|
||||
#[inline]
|
||||
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
|
||||
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
|
||||
Self { socket }
|
||||
unsafe {
|
||||
debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
|
||||
Self { socket }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
#![doc(cfg(windows))]
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
pub mod ffi;
|
||||
pub mod fs;
|
||||
|
@ -16,7 +16,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
|
||||
#[stable(feature = "process_extensions", since = "1.2.0")]
|
||||
impl FromRawHandle for process::Stdio {
|
||||
unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio {
|
||||
let handle = sys::handle::Handle::from_raw_handle(handle as *mut _);
|
||||
let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) };
|
||||
let io = sys::process::Stdio::Handle(handle);
|
||||
process::Stdio::from_inner(io)
|
||||
}
|
||||
@ -407,7 +407,7 @@ impl CommandExt for process::Command {
|
||||
attribute: usize,
|
||||
value: T,
|
||||
) -> &mut process::Command {
|
||||
self.as_inner_mut().raw_attribute(attribute, value);
|
||||
unsafe { self.as_inner_mut().raw_attribute(attribute, value) };
|
||||
self
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user