Skip to content

Commit 9a91f4f

Browse files
committed
Fix compilation on wasm32-wasip1
Signed-off-by: Jiahao XU <[email protected]>
1 parent 4c842c0 commit 9a91f4f

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
77
use crate::marker::PhantomData;
88
use crate::mem::ManuallyDrop;
99
#[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit")))]
10-
use crate::sys::{cvt, fd::FileDesc};
10+
use crate::sys::cvt;
1111
use crate::sys_common::{AsInner, FromInner, IntoInner};
1212
use crate::{fmt, fs, io};
1313

@@ -495,7 +495,7 @@ impl AsFd for io::PipeReader {
495495
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
496496
impl From<io::PipeReader> for OwnedFd {
497497
fn from(pipe: io::PipeReader) -> Self {
498-
FileDesc::into_inner(pipe.0)
498+
pipe.0.into_inner()
499499
}
500500
}
501501

@@ -509,20 +509,20 @@ impl AsFd for io::PipeWriter {
509509
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
510510
impl From<io::PipeWriter> for OwnedFd {
511511
fn from(pipe: io::PipeWriter) -> Self {
512-
FileDesc::into_inner(pipe.0)
512+
pipe.0.into_inner()
513513
}
514514
}
515515

516516
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
517517
impl From<OwnedFd> for io::PipeReader {
518518
fn from(owned_fd: OwnedFd) -> Self {
519-
Self(FileDesc::from_inner(owned_fd))
519+
Self(FromInner::from_inner(owned_fd))
520520
}
521521
}
522522

523523
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
524524
impl From<OwnedFd> for io::PipeWriter {
525525
fn from(owned_fd: OwnedFd) -> Self {
526-
Self(FileDesc::from_inner(owned_fd))
526+
Self(FromInner::from_inner(owned_fd))
527527
}
528528
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::os::unix::io::AsFd;
1515
use crate::os::unix::io::OwnedFd;
1616
#[cfg(target_os = "wasi")]
1717
use crate::os::wasi::io::OwnedFd;
18-
use crate::sys::fd::FileDesc;
19-
use crate::sys_common::{AsInner, IntoInner};
18+
use crate::sys_common::{AsInner, FromInner, IntoInner};
2019
use crate::{fs, io};
2120

2221
/// Raw file descriptors.
@@ -288,7 +287,7 @@ impl AsRawFd for io::PipeReader {
288287
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
289288
impl FromRawFd for io::PipeReader {
290289
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
291-
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
290+
Self::from_inner(unsafe { FromRawFd::from_raw_fd(raw_fd) })
292291
}
293292
}
294293

@@ -309,7 +308,7 @@ impl AsRawFd for io::PipeWriter {
309308
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
310309
impl FromRawFd for io::PipeWriter {
311310
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
312-
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
311+
Self::from_inner(unsafe { FromRawFd::from_raw_fd(raw_fd) })
313312
}
314313
}
315314

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn read2(p1: AnonPipe, _v1: &mut Vec<u8>, _p2: AnonPipe, _v2: &mut Vec<u8>)
5858

5959
impl FromInner<!> for AnonPipe {
6060
fn from_inner(inner: !) -> Self {
61-
Self(inner)
61+
inner
6262
}
6363
}
6464

@@ -67,3 +67,41 @@ impl IntoInner<!> for AnonPipe {
6767
self.0
6868
}
6969
}
70+
71+
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
72+
mod unix_traits {
73+
use super::AnonPipe;
74+
use crate::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
75+
use crate::sys_common::FromInner;
76+
77+
impl AsRawFd for AnonPipe {
78+
#[inline]
79+
fn as_raw_fd(&self) -> RawFd {
80+
self.0
81+
}
82+
}
83+
84+
impl AsFd for AnonPipe {
85+
fn as_fd(&self) -> BorrowedFd<'_> {
86+
self.0
87+
}
88+
}
89+
90+
impl IntoRawFd for AnonPipe {
91+
fn into_raw_fd(self) -> RawFd {
92+
self.0
93+
}
94+
}
95+
96+
impl FromRawFd for AnonPipe {
97+
unsafe fn from_raw_fd(_: RawFd) -> Self {
98+
panic!("creating pipe on this platform is unsupported!")
99+
}
100+
}
101+
102+
impl FromInner<OwnedFd> for AnonPipe {
103+
fn from_inner(_: OwnedFd) -> Self {
104+
panic!("creating pipe on this platform is unsupported!")
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)