diff options
| author | bors <bors@rust-lang.org> | 2024-10-10 01:12:11 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-10 01:12:11 +0000 | 
| commit | df1b5d3cc2117f1ee96abca25678bc5f5604d450 (patch) | |
| tree | b1e970cb6955c336272c0f11f0b043d4162afdfe /library/std/src | |
| parent | fc0f045dd1fe9b0f14f504d0513623342be6f0dc (diff) | |
| parent | 7a764894548c1367d9c2612b8a5d98853fc9aa13 (diff) | |
| download | rust-df1b5d3cc2117f1ee96abca25678bc5f5604d450.tar.gz rust-df1b5d3cc2117f1ee96abca25678bc5f5604d450.zip | |
Auto merge of #131466 - matthiaskrgr:rollup-3qtz83x, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #123951 (Reserve guarded string literals (RFC 3593)) - #130827 (Library: Rename "object safe" to "dyn compatible") - #131383 (Add docs about slicing slices at the ends) - #131403 (Fix needless_lifetimes in rustc_serialize) - #131417 (Fix methods alignment on mobile) - #131449 (Decouple WASIp2 sockets from WasiFd) - #131462 (Mention allocation errors for `open_buffered`) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/fs.rs | 3 | ||||
| -rw-r--r-- | library/std/src/keyword_docs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/os/wasi/mod.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys/pal/wasip2/net.rs | 74 | 
4 files changed, 63 insertions, 20 deletions
| diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 124ef121b18..675140ff18f 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -394,7 +394,8 @@ impl File { /// /// # Errors /// - /// This function will return an error if `path` does not already exist. + /// This function will return an error if `path` does not already exist, + /// or if memory allocation fails for the new buffer. /// Other errors may also be returned according to [`OpenOptions::open`]. /// /// # Examples diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs index 9f4d244b547..453b2708daa 100644 --- a/library/std/src/keyword_docs.rs +++ b/library/std/src/keyword_docs.rs @@ -2349,12 +2349,13 @@ mod async_keyword {} /// [`async`]: ../std/keyword.async.html mod await_keyword {} +// FIXME(dyn_compat_renaming): Update URL and link text. #[doc(keyword = "dyn")] // /// `dyn` is a prefix of a [trait object]'s type. /// /// The `dyn` keyword is used to highlight that calls to methods on the associated `Trait` -/// are [dynamically dispatched]. To use the trait this way, it must be 'object safe'. +/// are [dynamically dispatched]. To use the trait this way, it must be 'dyn-compatible'[^1]. /// /// Unlike generic parameters or `impl Trait`, the compiler does not know the concrete type that /// is being passed. That is, the type has been [erased]. @@ -2382,6 +2383,7 @@ mod await_keyword {} /// [ref-trait-obj]: ../reference/types/trait-object.html /// [ref-obj-safety]: ../reference/items/traits.html#object-safety /// [erased]: https://en.wikipedia.org/wiki/Type_erasure +/// [^1]: Formerly known as 'object safe'. mod dyn_keyword {} #[doc(keyword = "union")] diff --git a/library/std/src/os/wasi/mod.rs b/library/std/src/os/wasi/mod.rs index 33b50c9e53b..2ee6aa46600 100644 --- a/library/std/src/os/wasi/mod.rs +++ b/library/std/src/os/wasi/mod.rs @@ -36,6 +36,8 @@ pub mod ffi; pub mod fs; pub mod io; + +#[cfg(all(target_os = "wasi", target_env = "p1"))] pub mod net; /// A prelude for conveniently writing platform-specific code. diff --git a/library/std/src/sys/pal/wasip2/net.rs b/library/std/src/sys/pal/wasip2/net.rs index c40eb229ba9..06e623df843 100644 --- a/library/std/src/sys/pal/wasip2/net.rs +++ b/library/std/src/sys/pal/wasip2/net.rs @@ -2,13 +2,12 @@ use libc::{c_int, c_void, size_t}; -use super::fd::WasiFd; use crate::ffi::CStr; use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut}; use crate::net::{Shutdown, SocketAddr}; -use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; +use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::sys::unsupported; -use crate::sys_common::net::{TcpListener, getsockopt, setsockopt, sockaddr_to_addr}; +use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr}; use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::time::{Duration, Instant}; use crate::{cmp, mem, str}; @@ -71,7 +70,9 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> { pub fn init() {} -pub struct Socket(WasiFd); +pub struct WasiSocket(OwnedFd); + +pub struct Socket(WasiSocket); impl Socket { pub fn new(addr: &SocketAddr, ty: c_int) -> io::Result<Socket> { @@ -327,53 +328,90 @@ impl Socket { } } -impl AsInner<WasiFd> for Socket { +impl AsInner<OwnedFd> for WasiSocket { #[inline] - fn as_inner(&self) -> &WasiFd { + fn as_inner(&self) -> &OwnedFd { &self.0 } } -impl IntoInner<WasiFd> for Socket { - fn into_inner(self) -> WasiFd { +impl IntoInner<OwnedFd> for WasiSocket { + fn into_inner(self) -> OwnedFd { self.0 } } -impl FromInner<WasiFd> for Socket { - fn from_inner(inner: WasiFd) -> Socket { - Socket(inner) +impl FromInner<OwnedFd> for WasiSocket { + fn from_inner(owned_fd: OwnedFd) -> Self { + Self(owned_fd) } } -impl AsFd for Socket { +impl AsFd for WasiSocket { fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } -impl AsRawFd for Socket { +impl AsRawFd for WasiSocket { #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } } -impl IntoRawFd for Socket { +impl IntoRawFd for WasiSocket { fn into_raw_fd(self) -> RawFd { self.0.into_raw_fd() } } -impl FromRawFd for Socket { +impl FromRawFd for WasiSocket { unsafe fn from_raw_fd(raw_fd: RawFd) -> Self { unsafe { Self(FromRawFd::from_raw_fd(raw_fd)) } } } -impl AsInner<Socket> for TcpListener { +impl AsInner<WasiSocket> for Socket { + #[inline] + fn as_inner(&self) -> &WasiSocket { + &self.0 + } +} + +impl IntoInner<WasiSocket> for Socket { + fn into_inner(self) -> WasiSocket { + self.0 + } +} + +impl FromInner<WasiSocket> for Socket { + fn from_inner(sock: WasiSocket) -> Socket { + Socket(sock) + } +} + +impl AsFd for Socket { + fn as_fd(&self) -> BorrowedFd<'_> { + self.0.as_fd() + } +} + +impl AsRawFd for Socket { #[inline] - fn as_inner(&self) -> &Socket { - &self.socket() + fn as_raw_fd(&self) -> RawFd { + self.0.as_raw_fd() + } +} + +impl IntoRawFd for Socket { + fn into_raw_fd(self) -> RawFd { + self.0.into_raw_fd() + } +} + +impl FromRawFd for Socket { + unsafe fn from_raw_fd(raw_fd: RawFd) -> Self { + unsafe { Self(FromRawFd::from_raw_fd(raw_fd)) } } } | 
