diff options
| author | bors <bors@rust-lang.org> | 2022-05-15 18:52:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-15 18:52:28 +0000 |
| commit | 29e972dc608a0a2cb639decda1c9f30cb029e423 (patch) | |
| tree | e2ac285c7564d7d7d6c46e23d3ca906830f266ca /library/std/src | |
| parent | 0f202d22c5e759062de276cbf0c27ed69794cb65 (diff) | |
| parent | d56c59efdcb394c863c70a79bfbbe8ddfc1ece0a (diff) | |
| download | rust-29e972dc608a0a2cb639decda1c9f30cb029e423.tar.gz rust-29e972dc608a0a2cb639decda1c9f30cb029e423.zip | |
Auto merge of #97063 - Dylan-DPC:rollup-u5el7hb, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #96947 (Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket) - #97021 (Added note in documentation) - #97042 (Add new eslint rule about brace style) - #97060 (Fix use of SetHandleInformation on UWP) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/os/fd/owned.rs | 2 | ||||
| -rw-r--r-- | library/std/src/os/fd/tests.rs | 19 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/handle.rs | 1 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/mod.rs | 3 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/socket.rs | 3 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/tests.rs | 21 | ||||
| -rw-r--r-- | library/std/src/sys/windows/handle.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/windows/pipe.rs | 13 |
8 files changed, 62 insertions, 1 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index bfc5ce01564..53433823fbd 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -32,6 +32,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; // 32-bit c_int. Below is -2, in two's complement, but that only works out // because c_int is 32 bits. #[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] +#[rustc_nonnull_optimization_guaranteed] #[unstable(feature = "io_safety", issue = "87074")] pub struct BorrowedFd<'fd> { fd: RawFd, @@ -52,6 +53,7 @@ pub struct BorrowedFd<'fd> { // 32-bit c_int. Below is -2, in two's complement, but that only works out // because c_int is 32 bits. #[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] +#[rustc_nonnull_optimization_guaranteed] #[unstable(feature = "io_safety", issue = "87074")] pub struct OwnedFd { fd: RawFd, diff --git a/library/std/src/os/fd/tests.rs b/library/std/src/os/fd/tests.rs index 26ef93e3d71..b39863644f1 100644 --- a/library/std/src/os/fd/tests.rs +++ b/library/std/src/os/fd/tests.rs @@ -32,3 +32,22 @@ fn test_fd() { assert_eq!(stdin_as_file.as_fd().as_raw_fd(), raw_fd); assert_eq!(Into::<OwnedFd>::into(stdin_as_file).into_raw_fd(), raw_fd); } + +#[cfg(any(unix, target_os = "wasi"))] +#[test] +fn test_niche_optimizations() { + use crate::mem::size_of; + #[cfg(unix)] + use crate::os::unix::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; + #[cfg(target_os = "wasi")] + use crate::os::wasi::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; + + assert_eq!(size_of::<Option<OwnedFd>>(), size_of::<RawFd>()); + assert_eq!(size_of::<Option<BorrowedFd<'static>>>(), size_of::<RawFd>()); + unsafe { + assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN); + assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX); + assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MIN)).unwrap().into_raw_fd(), RawFd::MIN); + assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MAX)).unwrap().into_raw_fd(), RawFd::MAX); + } +} diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index f27970eaaf1..0ecac6b4475 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -206,6 +206,7 @@ impl OwnedHandle { } /// Allow child processes to inherit the handle. + #[cfg(not(target_vendor = "uwp"))] pub(crate) fn set_inheritable(&self) -> io::Result<()> { cvt(unsafe { c::SetHandleInformation( diff --git a/library/std/src/os/windows/io/mod.rs b/library/std/src/os/windows/io/mod.rs index 2f6f0769548..3325688e661 100644 --- a/library/std/src/os/windows/io/mod.rs +++ b/library/std/src/os/windows/io/mod.rs @@ -54,3 +54,6 @@ pub use handle::*; pub use raw::*; #[unstable(feature = "io_safety", issue = "87074")] pub use socket::*; + +#[cfg(test)] +mod tests; diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index c14a1d6192f..e23e1cf8cee 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -10,6 +10,7 @@ use crate::mem; use crate::mem::forget; use crate::sys; use crate::sys::c; +#[cfg(not(target_vendor = "uwp"))] use crate::sys::cvt; /// A borrowed socket. @@ -34,6 +35,7 @@ use crate::sys::cvt; target_pointer_width = "64", rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) )] +#[rustc_nonnull_optimization_guaranteed] #[unstable(feature = "io_safety", issue = "87074")] pub struct BorrowedSocket<'socket> { socket: RawSocket, @@ -56,6 +58,7 @@ pub struct BorrowedSocket<'socket> { target_pointer_width = "64", rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) )] +#[rustc_nonnull_optimization_guaranteed] #[unstable(feature = "io_safety", issue = "87074")] pub struct OwnedSocket { socket: RawSocket, diff --git a/library/std/src/os/windows/io/tests.rs b/library/std/src/os/windows/io/tests.rs new file mode 100644 index 00000000000..41734e52e8c --- /dev/null +++ b/library/std/src/os/windows/io/tests.rs @@ -0,0 +1,21 @@ +#[test] +fn test_niche_optimizations_socket() { + use crate::mem::size_of; + use crate::os::windows::io::{ + BorrowedSocket, FromRawSocket, IntoRawSocket, OwnedSocket, RawSocket, + }; + + assert_eq!(size_of::<Option<OwnedSocket>>(), size_of::<RawSocket>()); + assert_eq!(size_of::<Option<BorrowedSocket<'static>>>(), size_of::<RawSocket>(),); + unsafe { + #[cfg(target_pointer_width = "32")] + let (min, max) = (i32::MIN as u32, i32::MAX as u32); + #[cfg(target_pointer_width = "64")] + let (min, max) = (i64::MIN as u64, i64::MAX as u64); + + assert_eq!(OwnedSocket::from_raw_socket(min).into_raw_socket(), min); + assert_eq!(OwnedSocket::from_raw_socket(max).into_raw_socket(), max); + assert_eq!(Some(OwnedSocket::from_raw_socket(min)).unwrap().into_raw_socket(), min); + assert_eq!(Some(OwnedSocket::from_raw_socket(max)).unwrap().into_raw_socket(), max); + } +} diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index 3b609825a79..c319cb28630 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -221,6 +221,7 @@ impl Handle { Ok(Self(self.0.duplicate(access, inherit, options)?)) } + #[cfg(not(target_vendor = "uwp"))] pub(crate) fn set_inheritable(&self) -> io::Result<()> { self.0.set_inheritable() } diff --git a/library/std/src/sys/windows/pipe.rs b/library/std/src/sys/windows/pipe.rs index 928bf2439c3..2c586f1abe4 100644 --- a/library/std/src/sys/windows/pipe.rs +++ b/library/std/src/sys/windows/pipe.rs @@ -57,10 +57,21 @@ impl Pipes { } else { let (ours, theirs) = if ours_readable { (read, write) } else { (write, read) }; let ours = Handle::from_raw_handle(ours); + #[cfg(not(target_vendor = "uwp"))] let theirs = Handle::from_raw_handle(theirs); + #[cfg(target_vendor = "uwp")] + let mut theirs = Handle::from_raw_handle(theirs); if their_handle_inheritable { - theirs.set_inheritable()?; + #[cfg(not(target_vendor = "uwp"))] + { + theirs.set_inheritable()?; + } + + #[cfg(target_vendor = "uwp")] + { + theirs = theirs.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?; + } } Ok(Pipes { ours: AnonPipe::Sync(ours), theirs: AnonPipe::Sync(theirs) }) |
