Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 29e972d

Browse files
committed
Auto merge of rust-lang#97063 - Dylan-DPC:rollup-u5el7hb, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - rust-lang#96947 (Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket) - rust-lang#97021 (Added note in documentation) - rust-lang#97042 (Add new eslint rule about brace style) - rust-lang#97060 (Fix use of SetHandleInformation on UWP) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0f202d2 + d56c59e commit 29e972d

File tree

14 files changed

+123
-35
lines changed

14 files changed

+123
-35
lines changed

library/std/src/os/fd/owned.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
3232
// 32-bit c_int. Below is -2, in two's complement, but that only works out
3333
// because c_int is 32 bits.
3434
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
35+
#[rustc_nonnull_optimization_guaranteed]
3536
#[unstable(feature = "io_safety", issue = "87074")]
3637
pub struct BorrowedFd<'fd> {
3738
fd: RawFd,
@@ -52,6 +53,7 @@ pub struct BorrowedFd<'fd> {
5253
// 32-bit c_int. Below is -2, in two's complement, but that only works out
5354
// because c_int is 32 bits.
5455
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
56+
#[rustc_nonnull_optimization_guaranteed]
5557
#[unstable(feature = "io_safety", issue = "87074")]
5658
pub struct OwnedFd {
5759
fd: RawFd,

library/std/src/os/fd/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ fn test_fd() {
3232
assert_eq!(stdin_as_file.as_fd().as_raw_fd(), raw_fd);
3333
assert_eq!(Into::<OwnedFd>::into(stdin_as_file).into_raw_fd(), raw_fd);
3434
}
35+
36+
#[cfg(any(unix, target_os = "wasi"))]
37+
#[test]
38+
fn test_niche_optimizations() {
39+
use crate::mem::size_of;
40+
#[cfg(unix)]
41+
use crate::os::unix::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
42+
#[cfg(target_os = "wasi")]
43+
use crate::os::wasi::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
44+
45+
assert_eq!(size_of::<Option<OwnedFd>>(), size_of::<RawFd>());
46+
assert_eq!(size_of::<Option<BorrowedFd<'static>>>(), size_of::<RawFd>());
47+
unsafe {
48+
assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN);
49+
assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX);
50+
assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MIN)).unwrap().into_raw_fd(), RawFd::MIN);
51+
assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MAX)).unwrap().into_raw_fd(), RawFd::MAX);
52+
}
53+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl OwnedHandle {
206206
}
207207

208208
/// Allow child processes to inherit the handle.
209+
#[cfg(not(target_vendor = "uwp"))]
209210
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
210211
cvt(unsafe {
211212
c::SetHandleInformation(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ pub use handle::*;
5454
pub use raw::*;
5555
#[unstable(feature = "io_safety", issue = "87074")]
5656
pub use socket::*;
57+
58+
#[cfg(test)]
59+
mod tests;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::mem;
1010
use crate::mem::forget;
1111
use crate::sys;
1212
use crate::sys::c;
13+
#[cfg(not(target_vendor = "uwp"))]
1314
use crate::sys::cvt;
1415

1516
/// A borrowed socket.
@@ -34,6 +35,7 @@ use crate::sys::cvt;
3435
target_pointer_width = "64",
3536
rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE)
3637
)]
38+
#[rustc_nonnull_optimization_guaranteed]
3739
#[unstable(feature = "io_safety", issue = "87074")]
3840
pub struct BorrowedSocket<'socket> {
3941
socket: RawSocket,
@@ -56,6 +58,7 @@ pub struct BorrowedSocket<'socket> {
5658
target_pointer_width = "64",
5759
rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE)
5860
)]
61+
#[rustc_nonnull_optimization_guaranteed]
5962
#[unstable(feature = "io_safety", issue = "87074")]
6063
pub struct OwnedSocket {
6164
socket: RawSocket,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[test]
2+
fn test_niche_optimizations_socket() {
3+
use crate::mem::size_of;
4+
use crate::os::windows::io::{
5+
BorrowedSocket, FromRawSocket, IntoRawSocket, OwnedSocket, RawSocket,
6+
};
7+
8+
assert_eq!(size_of::<Option<OwnedSocket>>(), size_of::<RawSocket>());
9+
assert_eq!(size_of::<Option<BorrowedSocket<'static>>>(), size_of::<RawSocket>(),);
10+
unsafe {
11+
#[cfg(target_pointer_width = "32")]
12+
let (min, max) = (i32::MIN as u32, i32::MAX as u32);
13+
#[cfg(target_pointer_width = "64")]
14+
let (min, max) = (i64::MIN as u64, i64::MAX as u64);
15+
16+
assert_eq!(OwnedSocket::from_raw_socket(min).into_raw_socket(), min);
17+
assert_eq!(OwnedSocket::from_raw_socket(max).into_raw_socket(), max);
18+
assert_eq!(Some(OwnedSocket::from_raw_socket(min)).unwrap().into_raw_socket(), min);
19+
assert_eq!(Some(OwnedSocket::from_raw_socket(max)).unwrap().into_raw_socket(), max);
20+
}
21+
}

library/std/src/sys/windows/handle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl Handle {
221221
Ok(Self(self.0.duplicate(access, inherit, options)?))
222222
}
223223

224+
#[cfg(not(target_vendor = "uwp"))]
224225
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
225226
self.0.set_inheritable()
226227
}

library/std/src/sys/windows/pipe.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ impl Pipes {
5757
} else {
5858
let (ours, theirs) = if ours_readable { (read, write) } else { (write, read) };
5959
let ours = Handle::from_raw_handle(ours);
60+
#[cfg(not(target_vendor = "uwp"))]
6061
let theirs = Handle::from_raw_handle(theirs);
62+
#[cfg(target_vendor = "uwp")]
63+
let mut theirs = Handle::from_raw_handle(theirs);
6164

6265
if their_handle_inheritable {
63-
theirs.set_inheritable()?;
66+
#[cfg(not(target_vendor = "uwp"))]
67+
{
68+
theirs.set_inheritable()?;
69+
}
70+
71+
#[cfg(target_vendor = "uwp")]
72+
{
73+
theirs = theirs.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?;
74+
}
6475
}
6576

6677
Ok(Pipes { ours: AnonPipe::Sync(ours), theirs: AnonPipe::Sync(theirs) })

src/doc/unstable-book/src/compiler-flags/sanitizer.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ This feature allows for use of one of following sanitizers:
2222

2323
To enable a sanitizer compile with `-Zsanitizer=address`,`-Zsanitizer=cfi`,
2424
`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`, `-Zsanitizer=memory`,
25-
`-Zsanitizer=memtag`, or `-Zsanitizer=thread`.
25+
`-Zsanitizer=memtag`, or `-Zsanitizer=thread`. You might also need the `--target` and `build-std` flags. Example:
26+
```shell
27+
$ RUSTFLAGS=-Zsanitizer=address cargo build -Zbuild-std --target x86_64-unknown-linux-gnu
28+
```
2629

2730
# AddressSanitizer
2831

src/librustdoc/html/static/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ module.exports = {
2929
"no-var": ["error"],
3030
"prefer-const": ["error"],
3131
"prefer-arrow-callback": ["error"],
32+
"brace-style": [
33+
"error",
34+
"1tbs",
35+
{ "allowSingleLine": false }
36+
],
3237
}
3338
};

0 commit comments

Comments
 (0)