Skip to content

Commit bc50979

Browse files
authored
Unrolled build for rust-lang#128162
Rollup merge of rust-lang#128162 - ChrisDenton:cleanup, r=joboet Cleanup sys module to match house style This moves a test file out of sys as it's just testing std types. Also cleans up some assorted bits including making the `use` statements match the house style.
2 parents 28a58f2 + e84a7d9 commit bc50979

File tree

7 files changed

+28
-41
lines changed

7 files changed

+28
-41
lines changed

library/std/src/sys/anonymous_pipe/tests.rs library/std/src/pipe/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::io::{Read, Write};
22
use crate::pipe::pipe;
33

44
#[test]
5+
#[cfg(all(windows, unix, not(miri)))]
56
fn pipe_creation_clone_and_rw() {
67
let (rx, tx) = pipe().unwrap();
78

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
#![forbid(unsafe_op_in_unsafe_fn)]
2+
13
cfg_if::cfg_if! {
24
if #[cfg(unix)] {
35
mod unix;
4-
pub(crate) use unix::{AnonPipe, pipe};
5-
6-
#[cfg(all(test, not(miri)))]
7-
mod tests;
6+
pub use unix::{AnonPipe, pipe};
87
} else if #[cfg(windows)] {
98
mod windows;
10-
pub(crate) use windows::{AnonPipe, pipe};
11-
12-
#[cfg(all(test, not(miri)))]
13-
mod tests;
9+
pub use windows::{AnonPipe, pipe};
1410
} else {
1511
mod unsupported;
16-
pub(crate) use unsupported::{AnonPipe, pipe};
12+
pub use unsupported::{AnonPipe, pipe};
1713
}
1814
}

library/std/src/sys/anonymous_pipe/unix.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::sys::fd::FileDesc;
66
use crate::sys::pipe::anon_pipe;
77
use crate::sys_common::{FromInner, IntoInner};
88

9-
pub(crate) type AnonPipe = FileDesc;
9+
pub type AnonPipe = FileDesc;
1010

1111
#[inline]
12-
pub(crate) fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
12+
pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
1313
anon_pipe().map(|(rx, wx)| (rx.into_inner(), wx.into_inner()))
1414
}
1515

@@ -34,7 +34,7 @@ impl From<PipeReader> for OwnedFd {
3434
#[unstable(feature = "anonymous_pipe", issue = "127154")]
3535
impl FromRawFd for PipeReader {
3636
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
37-
Self(FileDesc::from_raw_fd(raw_fd))
37+
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
3838
}
3939
}
4040
#[unstable(feature = "anonymous_pipe", issue = "127154")]
@@ -71,7 +71,7 @@ impl From<PipeWriter> for OwnedFd {
7171
#[unstable(feature = "anonymous_pipe", issue = "127154")]
7272
impl FromRawFd for PipeWriter {
7373
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
74-
Self(FileDesc::from_raw_fd(raw_fd))
74+
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
7575
}
7676
}
7777
#[unstable(feature = "anonymous_pipe", issue = "127154")]

library/std/src/sys/anonymous_pipe/unsupported.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::io;
22
use crate::pipe::{PipeReader, PipeWriter};
33
use crate::process::Stdio;
4-
pub(crate) use crate::sys::pipe::AnonPipe;
4+
pub use crate::sys::pipe::AnonPipe;
55

66
#[inline]
7-
pub(crate) fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
7+
pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
88
Err(io::Error::UNSUPPORTED_PLATFORM)
99
}
1010

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

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
use crate::io;
21
use crate::os::windows::io::{
32
AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle,
43
};
54
use crate::pipe::{PipeReader, PipeWriter};
65
use crate::process::Stdio;
6+
use crate::sys::c;
77
use crate::sys::handle::Handle;
8-
use crate::sys::pipe::unnamed_anon_pipe;
98
use crate::sys_common::{FromInner, IntoInner};
9+
use crate::{io, ptr};
1010

11-
pub(crate) type AnonPipe = Handle;
11+
pub type AnonPipe = Handle;
1212

13-
#[inline]
14-
pub(crate) fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
15-
unnamed_anon_pipe().map(|(rx, wx)| (rx.into_inner(), wx.into_inner()))
13+
pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
14+
let mut read_pipe = c::INVALID_HANDLE_VALUE;
15+
let mut write_pipe = c::INVALID_HANDLE_VALUE;
16+
17+
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
18+
19+
if ret == 0 {
20+
Err(io::Error::last_os_error())
21+
} else {
22+
unsafe { Ok((Handle::from_raw_handle(read_pipe), Handle::from_raw_handle(write_pipe))) }
23+
}
1624
}
1725

1826
#[unstable(feature = "anonymous_pipe", issue = "127154")]
@@ -31,7 +39,7 @@ impl AsRawHandle for PipeReader {
3139
#[unstable(feature = "anonymous_pipe", issue = "127154")]
3240
impl FromRawHandle for PipeReader {
3341
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self {
34-
Self(Handle::from_raw_handle(raw_handle))
42+
unsafe { Self(Handle::from_raw_handle(raw_handle)) }
3543
}
3644
}
3745
#[unstable(feature = "anonymous_pipe", issue = "127154")]
@@ -70,7 +78,7 @@ impl AsRawHandle for PipeWriter {
7078
#[unstable(feature = "anonymous_pipe", issue = "127154")]
7179
impl FromRawHandle for PipeWriter {
7280
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self {
73-
Self(Handle::from_raw_handle(raw_handle))
81+
unsafe { Self(Handle::from_raw_handle(raw_handle)) }
7482
}
7583
}
7684
#[unstable(feature = "anonymous_pipe", issue = "127154")]

library/std/src/sys/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod pal;
77

88
mod personality;
99

10-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
1110
pub mod anonymous_pipe;
1211
pub mod backtrace;
1312
pub mod cmath;

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

-17
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,6 @@ pub struct Pipes {
3636
pub theirs: AnonPipe,
3737
}
3838

39-
/// Create true unnamed anonymous pipe.
40-
pub fn unnamed_anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
41-
let mut read_pipe = c::INVALID_HANDLE_VALUE;
42-
let mut write_pipe = c::INVALID_HANDLE_VALUE;
43-
44-
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
45-
46-
if ret == 0 {
47-
Err(io::Error::last_os_error())
48-
} else {
49-
Ok((
50-
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(read_pipe) }),
51-
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(write_pipe) }),
52-
))
53-
}
54-
}
55-
5639
/// Although this looks similar to `anon_pipe` in the Unix module it's actually
5740
/// subtly different. Here we'll return two pipes in the `Pipes` return value,
5841
/// but one is intended for "us" where as the other is intended for "someone

0 commit comments

Comments
 (0)