From 5363f350887b1e5b5dd21a86f88c8af9d7fea6da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:25 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/io-lifetimes/src/example_ffi.rs | 4 +- vendor/io-lifetimes/src/impls_async_std.rs | 16 ----- vendor/io-lifetimes/src/impls_mio.rs | 24 -------- vendor/io-lifetimes/src/impls_os_pipe.rs | 5 -- vendor/io-lifetimes/src/impls_socket2.rs | 3 - vendor/io-lifetimes/src/impls_std.rs | 2 + vendor/io-lifetimes/src/impls_std_views.rs | 31 ---------- vendor/io-lifetimes/src/lib.rs | 56 ++++++++++-------- vendor/io-lifetimes/src/portability.rs | 93 +++++++++++++++--------------- vendor/io-lifetimes/src/traits.rs | 72 ++++++++++++++--------- vendor/io-lifetimes/src/types.rs | 34 ----------- vendor/io-lifetimes/src/views.rs | 73 +++++++++++++++++++++++ 12 files changed, 200 insertions(+), 213 deletions(-) delete mode 100644 vendor/io-lifetimes/src/impls_std_views.rs (limited to 'vendor/io-lifetimes/src') diff --git a/vendor/io-lifetimes/src/example_ffi.rs b/vendor/io-lifetimes/src/example_ffi.rs index 8f7c238ba..0b31b9ec2 100644 --- a/vendor/io-lifetimes/src/example_ffi.rs +++ b/vendor/io-lifetimes/src/example_ffi.rs @@ -1,6 +1,6 @@ //! This is just a sample of what FFI using this crate can look like. -#![cfg_attr(not(rustc_attrs), allow(unused_imports))] +#![cfg_attr(not(io_safety_is_in_std), allow(unused_imports))] #![allow(missing_docs)] #[cfg(any(unix, target_os = "wasi"))] @@ -23,7 +23,7 @@ use { }; // Declare a few FFI functions ourselves, to show off the FFI ergonomics. -#[cfg(all(rustc_attrs, any(unix, target_os = "wasi")))] +#[cfg(all(io_safety_is_in_std, any(unix, target_os = "wasi")))] extern "C" { pub fn open(pathname: *const c_char, flags: c_int, ...) -> Option; } diff --git a/vendor/io-lifetimes/src/impls_async_std.rs b/vendor/io-lifetimes/src/impls_async_std.rs index 534700486..7223e9955 100644 --- a/vendor/io-lifetimes/src/impls_async_std.rs +++ b/vendor/io-lifetimes/src/impls_async_std.rs @@ -2,7 +2,6 @@ //! future, we'll prefer to have crates provide their own impls; this is //! just a temporary measure. -use crate::views::{FilelikeViewType, SocketlikeViewType}; #[cfg(any(unix, target_os = "wasi"))] use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; #[cfg(windows)] @@ -101,8 +100,6 @@ impl From for async_std::fs::File { } } -unsafe impl SocketlikeViewType for async_std::net::TcpStream {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for async_std::net::TcpStream { #[inline] @@ -183,8 +180,6 @@ impl From for async_std::net::TcpStream { } } -unsafe impl SocketlikeViewType for async_std::net::TcpListener {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for async_std::net::TcpListener { #[inline] @@ -265,8 +260,6 @@ impl From for async_std::net::TcpListener { } } -unsafe impl SocketlikeViewType for async_std::net::UdpSocket {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for async_std::net::UdpSocket { #[inline] @@ -395,9 +388,6 @@ impl AsHandle for async_std::io::Stderr { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {} - #[cfg(unix)] impl AsFd for async_std::os::unix::net::UnixStream { #[inline] @@ -438,9 +428,6 @@ impl From for async_std::os::unix::net::UnixStream { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {} - #[cfg(unix)] impl AsFd for async_std::os::unix::net::UnixListener { #[inline] @@ -481,9 +468,6 @@ impl From for async_std::os::unix::net::UnixListener { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {} - #[cfg(unix)] impl AsFd for async_std::os::unix::net::UnixDatagram { #[inline] diff --git a/vendor/io-lifetimes/src/impls_mio.rs b/vendor/io-lifetimes/src/impls_mio.rs index 246f3b93f..486274b09 100644 --- a/vendor/io-lifetimes/src/impls_mio.rs +++ b/vendor/io-lifetimes/src/impls_mio.rs @@ -2,9 +2,6 @@ //! future, we'll prefer to have crates provide their own impls; this is //! just a temporary measure. -#[cfg(unix)] -use crate::views::FilelikeViewType; -use crate::views::SocketlikeViewType; #[cfg(any(unix, target_os = "wasi"))] use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; #[cfg(windows)] @@ -16,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; #[cfg(windows)] use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket}; -unsafe impl SocketlikeViewType for mio::net::TcpStream {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for mio::net::TcpStream { #[inline] @@ -98,8 +93,6 @@ impl From for mio::net::TcpStream { } } -unsafe impl SocketlikeViewType for mio::net::TcpListener {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for mio::net::TcpListener { #[inline] @@ -180,8 +173,6 @@ impl From for mio::net::TcpListener { } } -unsafe impl SocketlikeViewType for mio::net::UdpSocket {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for mio::net::UdpSocket { #[inline] @@ -262,9 +253,6 @@ impl From for mio::net::UdpSocket { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for mio::net::UnixDatagram {} - #[cfg(unix)] impl AsFd for mio::net::UnixDatagram { #[inline] @@ -305,9 +293,6 @@ impl From for mio::net::UnixDatagram { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for mio::net::UnixListener {} - #[cfg(unix)] impl AsFd for mio::net::UnixListener { #[inline] @@ -348,9 +333,6 @@ impl From for mio::net::UnixListener { } } -#[cfg(unix)] -unsafe impl SocketlikeViewType for mio::net::UnixStream {} - #[cfg(unix)] impl AsFd for mio::net::UnixStream { #[inline] @@ -391,9 +373,6 @@ impl From for mio::net::UnixStream { } } -#[cfg(unix)] -unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {} - #[cfg(unix)] impl AsFd for mio::unix::pipe::Receiver { #[inline] @@ -434,9 +413,6 @@ impl From for mio::unix::pipe::Receiver { } } -#[cfg(unix)] -unsafe impl FilelikeViewType for mio::unix::pipe::Sender {} - #[cfg(unix)] impl AsFd for mio::unix::pipe::Sender { #[inline] diff --git a/vendor/io-lifetimes/src/impls_os_pipe.rs b/vendor/io-lifetimes/src/impls_os_pipe.rs index e0544873e..4c1d1bf67 100644 --- a/vendor/io-lifetimes/src/impls_os_pipe.rs +++ b/vendor/io-lifetimes/src/impls_os_pipe.rs @@ -2,7 +2,6 @@ //! future, we'll prefer to have crates provide their own impls; this is //! just a temporary measure. -use crate::views::FilelikeViewType; #[cfg(any(unix, target_os = "wasi"))] use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; #[cfg(windows)] @@ -14,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; #[cfg(windows)] use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; -unsafe impl FilelikeViewType for os_pipe::PipeReader {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for os_pipe::PipeReader { #[inline] @@ -96,8 +93,6 @@ impl From for os_pipe::PipeReader { } } -unsafe impl FilelikeViewType for os_pipe::PipeWriter {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for os_pipe::PipeWriter { #[inline] diff --git a/vendor/io-lifetimes/src/impls_socket2.rs b/vendor/io-lifetimes/src/impls_socket2.rs index fbfeb67d7..3dc4f9eea 100644 --- a/vendor/io-lifetimes/src/impls_socket2.rs +++ b/vendor/io-lifetimes/src/impls_socket2.rs @@ -2,7 +2,6 @@ //! future, we'll prefer to have crates provide their own impls; this is //! just a temporary measure. -use crate::views::SocketlikeViewType; #[cfg(any(unix, target_os = "wasi"))] use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; #[cfg(windows)] @@ -14,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; #[cfg(windows)] use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket}; -unsafe impl SocketlikeViewType for socket2::Socket {} - #[cfg(any(unix, target_os = "wasi"))] impl AsFd for socket2::Socket { #[inline] diff --git a/vendor/io-lifetimes/src/impls_std.rs b/vendor/io-lifetimes/src/impls_std.rs index 27275fa68..145bb1982 100644 --- a/vendor/io-lifetimes/src/impls_std.rs +++ b/vendor/io-lifetimes/src/impls_std.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] // Don't warn on `IntoFd` and `FromFd` impls. + #[cfg(any(unix, target_os = "wasi"))] use crate::{AsFd, FromFd, IntoFd}; #[cfg(windows)] diff --git a/vendor/io-lifetimes/src/impls_std_views.rs b/vendor/io-lifetimes/src/impls_std_views.rs deleted file mode 100644 index ffa013ffa..000000000 --- a/vendor/io-lifetimes/src/impls_std_views.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::views::{FilelikeViewType, SocketlikeViewType}; -#[cfg(any(unix, target_os = "wasi"))] -use crate::OwnedFd; -#[cfg(windows)] -use crate::{OwnedHandle, OwnedSocket}; - -#[cfg(any(unix, target_os = "wasi"))] -unsafe impl FilelikeViewType for OwnedFd {} - -#[cfg(windows)] -unsafe impl FilelikeViewType for OwnedHandle {} - -#[cfg(windows)] -unsafe impl SocketlikeViewType for OwnedSocket {} - -unsafe impl FilelikeViewType for std::fs::File {} - -unsafe impl SocketlikeViewType for std::net::TcpStream {} - -unsafe impl SocketlikeViewType for std::net::TcpListener {} - -unsafe impl SocketlikeViewType for std::net::UdpSocket {} - -#[cfg(unix)] -unsafe impl SocketlikeViewType for std::os::unix::net::UnixStream {} - -#[cfg(unix)] -unsafe impl SocketlikeViewType for std::os::unix::net::UnixListener {} - -#[cfg(unix)] -unsafe impl SocketlikeViewType for std::os::unix::net::UnixDatagram {} diff --git a/vendor/io-lifetimes/src/lib.rs b/vendor/io-lifetimes/src/lib.rs index 5e2a9d19f..da5e740cf 100644 --- a/vendor/io-lifetimes/src/lib.rs +++ b/vendor/io-lifetimes/src/lib.rs @@ -28,47 +28,47 @@ //! [from+into conversions]: FromFilelike::from_into_filelike #![deny(missing_docs)] -#![cfg_attr(rustc_attrs, feature(rustc_attrs))] -#![cfg_attr(all(io_lifetimes_use_std, target_os = "wasi"), feature(wasi_ext))] -#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] +// Work around https://github.com/rust-lang/rust/issues/103306. +#![cfg_attr(all(wasi_ext, target_os = "wasi"), feature(wasi_ext))] mod portability; mod traits; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] mod types; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] mod impls_std; -mod impls_std_views; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] pub use traits::AsFd; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] pub use traits::{AsHandle, AsSocket}; #[cfg(any(unix, target_os = "wasi"))] +#[allow(deprecated)] pub use traits::{FromFd, IntoFd}; #[cfg(windows)] +#[allow(deprecated)] pub use traits::{FromHandle, FromSocket, IntoHandle, IntoSocket}; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] pub use types::{BorrowedFd, OwnedFd}; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] pub use types::{ BorrowedHandle, BorrowedSocket, HandleOrInvalid, InvalidHandleError, NullHandleError, OwnedHandle, OwnedSocket, }; -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(unix)] pub use std::os::unix::io::{AsFd, BorrowedFd, OwnedFd}; -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(target_os = "wasi")] pub use std::os::wasi::io::{AsFd, BorrowedFd, OwnedFd}; -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(windows)] pub use std::os::windows::io::{ AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, HandleOrInvalid, InvalidHandleError, @@ -86,16 +86,18 @@ pub use std::os::windows::io::{ // // So we define `FromFd`/`IntoFd` traits, and implement them in terms of // `From`/`Into`, -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(any(unix, target_os = "wasi"))] +#[allow(deprecated)] impl> FromFd for T { #[inline] fn from_fd(owned_fd: OwnedFd) -> Self { owned_fd.into() } } -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(any(unix, target_os = "wasi"))] +#[allow(deprecated)] impl IntoFd for T where OwnedFd: From, @@ -106,16 +108,18 @@ where } } -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(windows)] +#[allow(deprecated)] impl> FromHandle for T { #[inline] fn from_handle(owned_handle: OwnedHandle) -> Self { owned_handle.into() } } -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(windows)] +#[allow(deprecated)] impl IntoHandle for T where OwnedHandle: From, @@ -126,16 +130,18 @@ where } } -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(windows)] +#[allow(deprecated)] impl> FromSocket for T { #[inline] fn from_socket(owned_socket: OwnedSocket) -> Self { owned_socket.into() } } -#[cfg(io_lifetimes_use_std)] +#[cfg(io_safety_is_in_std)] #[cfg(windows)] +#[allow(deprecated)] impl IntoSocket for T where OwnedSocket: From, @@ -158,22 +164,22 @@ pub mod views; // Ideally, we'd want crates to implement our traits themselves. But for now, // while we're prototyping, we provide a few impls on foreign types. -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "async-std")] mod impls_async_std; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "fs-err")] mod impls_fs_err; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "mio")] mod impls_mio; #[cfg(not(target_os = "wasi"))] -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "os_pipe")] mod impls_os_pipe; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "socket2")] mod impls_socket2; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(feature = "tokio")] mod impls_tokio; diff --git a/vendor/io-lifetimes/src/portability.rs b/vendor/io-lifetimes/src/portability.rs index ee9057501..eb630ce9f 100644 --- a/vendor/io-lifetimes/src/portability.rs +++ b/vendor/io-lifetimes/src/portability.rs @@ -6,12 +6,9 @@ use crate::views::{FilelikeView, FilelikeViewType, SocketlikeView, SocketlikeViewType}; #[cfg(any(unix, target_os = "wasi"))] -use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use crate::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] -use crate::{ - AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, FromHandle, FromSocket, IntoHandle, - IntoSocket, OwnedHandle, OwnedSocket, -}; +use crate::{AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, OwnedHandle, OwnedSocket}; /// A reference to a filelike object. /// @@ -104,6 +101,8 @@ pub trait AsFilelike: AsFd { /// ``` /// /// [`File`]: std::fs::File + /// [`Read`]: std::io::Read + /// [`Write`]: std::io::Write fn as_filelike_view(&self) -> FilelikeView<'_, Target>; } @@ -155,6 +154,8 @@ pub trait AsFilelike: AsHandle { /// ``` /// /// [`File`]: std::fs::File + /// [`Read`]: std::io::Read + /// [`Write`]: std::io::Write fn as_filelike_view(&self) -> FilelikeView<'_, Target>; } @@ -195,6 +196,8 @@ pub trait AsSocketlike: AsFd { /// ``` /// /// [`TcpStream`]: std::net::TcpStream + /// [`Read`]: std::io::Read + /// [`Write`]: std::io::Write fn as_socketlike_view(&self) -> SocketlikeView<'_, Target>; } @@ -254,10 +257,10 @@ impl AsSocketlike for T { /// A portable trait to express the ability to consume an object and acquire /// ownership of its filelike object. /// -/// This is a portability abstraction over Unix-like [`IntoFd`] and Windows' -/// `IntoHandle`. +/// This is a portability abstraction over Unix-like [`Into`] and Windows' +/// `Into`. #[cfg(any(unix, target_os = "wasi"))] -pub trait IntoFilelike: IntoFd { +pub trait IntoFilelike: Into { /// Consumes this object, returning the underlying filelike object. /// /// # Example @@ -275,58 +278,58 @@ pub trait IntoFilelike: IntoFd { } #[cfg(any(unix, target_os = "wasi"))] -impl IntoFilelike for T { +impl> IntoFilelike for T { #[inline] fn into_filelike(self) -> OwnedFilelike { - self.into_fd() + self.into() } } /// A portable trait to express the ability to consume an object and acquire /// ownership of its filelike object. /// -/// This is a portability abstraction over Unix-like `IntoFd` and Windows' -/// [`IntoHandle`]. +/// This is a portability abstraction over Unix-like `Into` and Windows' +/// [`Into`]. #[cfg(windows)] -pub trait IntoFilelike: IntoHandle { +pub trait IntoFilelike: Into { /// Consumes this object, returning the underlying filelike object. fn into_filelike(self) -> OwnedFilelike; } #[cfg(windows)] -impl IntoFilelike for T { +impl> IntoFilelike for T { #[inline] fn into_filelike(self) -> OwnedFilelike { - self.into_handle() + self.into() } } /// A portable trait to express the ability to consume an object and acquire /// ownership of its socketlike object. /// -/// This is a portability abstraction over Unix-like [`IntoFd`] and Windows' -/// `IntoSocket`. +/// This is a portability abstraction over Unix-like [`Into`] and Windows' +/// `Into`. #[cfg(any(unix, target_os = "wasi"))] -pub trait IntoSocketlike: IntoFd { +pub trait IntoSocketlike: Into { /// Consumes this object, returning the underlying socketlike object. fn into_socketlike(self) -> OwnedSocketlike; } #[cfg(any(unix, target_os = "wasi"))] -impl IntoSocketlike for T { +impl> IntoSocketlike for T { #[inline] fn into_socketlike(self) -> OwnedSocketlike { - self.into_fd() + self.into() } } /// A portable trait to express the ability to consume an object and acquire /// ownership of its socketlike object. /// -/// This is a portability abstraction over Unix-like `IntoFd` and Windows' -/// [`IntoSocket`]. +/// This is a portability abstraction over Unix-like `Into` and Windows' +/// [`Into`]. #[cfg(windows)] -pub trait IntoSocketlike: IntoSocket { +pub trait IntoSocketlike: Into { /// Consumes this object, returning the underlying socketlike object. /// /// # Example @@ -344,21 +347,21 @@ pub trait IntoSocketlike: IntoSocket { } #[cfg(windows)] -impl IntoSocketlike for T { +impl> IntoSocketlike for T { #[inline] fn into_socketlike(self) -> OwnedSocketlike { - self.into_socket() + self.into() } } /// A portable trait to express the ability to construct an object from a /// filelike object. /// -/// This is a portability abstraction over Unix-like [`FromFd`] and Windows' -/// `FromHandle`. It also provides the `from_into_filelike` convenience +/// This is a portability abstraction over Unix-like [`From`] and Windows' +/// `From`. It also provides the `from_into_filelike` convenience /// function providing simplified from+into conversions. #[cfg(any(unix, target_os = "wasi"))] -pub trait FromFilelike: FromFd { +pub trait FromFilelike: From { /// Constructs a new instance of `Self` from the given filelike object. /// /// # Example @@ -393,10 +396,10 @@ pub trait FromFilelike: FromFd { } #[cfg(any(unix, target_os = "wasi"))] -impl FromFilelike for T { +impl> FromFilelike for T { #[inline] fn from_filelike(owned: OwnedFilelike) -> Self { - Self::from_fd(owned) + Self::from(owned) } #[inline] @@ -408,11 +411,11 @@ impl FromFilelike for T { /// A portable trait to express the ability to construct an object from a /// filelike object. /// -/// This is a portability abstraction over Unix-like `FromFd` and Windows' -/// [`FromHandle`]. It also provides the `from_into_filelike` convenience +/// This is a portability abstraction over Unix-like `From` and Windows' +/// [`From`]. It also provides the `from_into_filelike` convenience /// function providing simplified from+into conversions. #[cfg(windows)] -pub trait FromFilelike: FromHandle { +pub trait FromFilelike: From { /// Constructs a new instance of `Self` from the given filelike object. /// /// # Example @@ -447,10 +450,10 @@ pub trait FromFilelike: FromHandle { } #[cfg(windows)] -impl FromFilelike for T { +impl> FromFilelike for T { #[inline] fn from_filelike(owned: OwnedFilelike) -> Self { - Self::from_handle(owned) + Self::from(owned) } #[inline] @@ -462,11 +465,11 @@ impl FromFilelike for T { /// A portable trait to express the ability to construct an object from a /// socketlike object. /// -/// This is a portability abstraction over Unix-like [`FromFd`] and Windows' -/// `FromSocket`. It also provides the `from_into_socketlike` convenience +/// This is a portability abstraction over Unix-like [`From`] and Windows' +/// `From It also provides the `from_into_socketlike` convenience /// function providing simplified from+into conversions. #[cfg(any(unix, target_os = "wasi"))] -pub trait FromSocketlike: FromFd { +pub trait FromSocketlike: From { /// Constructs a new instance of `Self` from the given socketlike object. fn from_socketlike(owned: OwnedSocketlike) -> Self; @@ -476,10 +479,10 @@ pub trait FromSocketlike: FromFd { } #[cfg(any(unix, target_os = "wasi"))] -impl FromSocketlike for T { +impl> FromSocketlike for T { #[inline] fn from_socketlike(owned: OwnedSocketlike) -> Self { - Self::from_fd(owned) + Self::from(owned) } #[inline] @@ -491,11 +494,11 @@ impl FromSocketlike for T { /// A portable trait to express the ability to construct an object from a /// socketlike object. /// -/// This is a portability abstraction over Unix-like `FromFd` and Windows' -/// [`FromSocket`]. It also provides the `from_into_socketlike` convenience +/// This is a portability abstraction over Unix-like `From` and Windows' +/// [`From`]. It also provides the `from_into_socketlike` convenience /// function providing simplified from+into conversions. #[cfg(windows)] -pub trait FromSocketlike: FromSocket { +pub trait FromSocketlike: From { /// Constructs a new instance of `Self` from the given socketlike object. fn from_socketlike(owned: OwnedSocketlike) -> Self; @@ -505,10 +508,10 @@ pub trait FromSocketlike: FromSocket { } #[cfg(windows)] -impl FromSocketlike for T { +impl> FromSocketlike for T { #[inline] fn from_socketlike(owned: OwnedSocketlike) -> Self { - Self::from_socket(owned) + Self::from(owned) } #[inline] diff --git a/vendor/io-lifetimes/src/traits.rs b/vendor/io-lifetimes/src/traits.rs index 788045208..7fb9a5bdb 100644 --- a/vendor/io-lifetimes/src/traits.rs +++ b/vendor/io-lifetimes/src/traits.rs @@ -1,9 +1,9 @@ -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] use crate::BorrowedFd; #[cfg(any(unix, target_os = "wasi"))] use crate::OwnedFd; -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] use crate::{BorrowedHandle, BorrowedSocket}; #[cfg(windows)] @@ -14,7 +14,7 @@ use crate::{OwnedHandle, OwnedSocket}; /// This is only available on unix platforms and must be imported in order to /// call the method. Windows platforms have a corresponding `AsHandle` and /// `AsSocket` set of traits. -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] pub trait AsFd { /// Borrows the file descriptor. @@ -22,7 +22,6 @@ pub trait AsFd { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{AsFd, BorrowedFd}; @@ -35,7 +34,7 @@ pub trait AsFd { } /// A trait to borrow the handle from an underlying object. -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] pub trait AsHandle { /// Borrows the handle. @@ -43,7 +42,6 @@ pub trait AsHandle { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{AsHandle, BorrowedHandle}; @@ -56,7 +54,7 @@ pub trait AsHandle { } /// A trait to borrow the socket from an underlying object. -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] pub trait AsSocket { /// Borrows the socket. @@ -66,13 +64,16 @@ pub trait AsSocket { /// A trait to express the ability to consume an object and acquire ownership /// of its file descriptor. #[cfg(any(unix, target_os = "wasi"))] +#[deprecated( + since = "1.0.0", + note = "`IntoFd` is replaced by `From<...> for OwnedFd` or `Into`" +)] pub trait IntoFd { /// Consumes this object, returning the underlying file descriptor. /// /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{IntoFd, OwnedFd}; @@ -87,13 +88,16 @@ pub trait IntoFd { /// A trait to express the ability to consume an object and acquire ownership /// of its handle. #[cfg(windows)] +#[deprecated( + since = "1.0.0", + note = "`IntoHandle` is replaced by `From<...> for OwnedHandle` or `Into`" +)] pub trait IntoHandle { /// Consumes this object, returning the underlying handle. /// /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{IntoHandle, OwnedHandle}; @@ -108,6 +112,10 @@ pub trait IntoHandle { /// A trait to express the ability to consume an object and acquire ownership /// of its socket. #[cfg(windows)] +#[deprecated( + since = "1.0.0", + note = "`IntoSocket` is replaced by `From<...> for OwnedSocket` or `Into`" +)] pub trait IntoSocket { /// Consumes this object, returning the underlying socket. fn into_socket(self) -> OwnedSocket; @@ -122,7 +130,6 @@ pub trait FromFd { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{FromFd, IntoFd, OwnedFd}; @@ -132,6 +139,10 @@ pub trait FromFd { /// let f = File::from_fd(owned_fd); /// # Ok::<(), io::Error>(()) /// ``` + #[deprecated( + since = "1.0.0", + note = "`FromFd::from_fd` is replaced by `From::from`" + )] fn from_fd(owned: OwnedFd) -> Self; /// Constructs a new instance of `Self` from the given file descriptor @@ -140,7 +151,6 @@ pub trait FromFd { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{FromFd, IntoFd}; @@ -150,11 +160,11 @@ pub trait FromFd { /// # Ok::<(), io::Error>(()) /// ``` #[inline] - fn from_into_fd(into_owned: Owned) -> Self + fn from_into_fd>(into_owned: Owned) -> Self where - Self: Sized, + Self: Sized + From, { - Self::from_fd(into_owned.into_fd()) + Self::from(into_owned.into()) } } @@ -166,7 +176,6 @@ pub trait FromHandle { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{FromHandle, IntoHandle, OwnedHandle}; @@ -176,6 +185,10 @@ pub trait FromHandle { /// let f = File::from_handle(owned_handle); /// # Ok::<(), io::Error>(()) /// ``` + #[deprecated( + since = "1.0.0", + note = "`FromHandle::from_handle` is replaced by `From::from`" + )] fn from_handle(owned: OwnedHandle) -> Self; /// Constructs a new instance of `Self` from the given handle converted @@ -184,7 +197,6 @@ pub trait FromHandle { /// # Example /// /// ```rust,no_run - /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] /// use std::fs::File; /// # use std::io; /// use io_lifetimes::{FromHandle, IntoHandle}; @@ -194,11 +206,11 @@ pub trait FromHandle { /// # Ok::<(), io::Error>(()) /// ``` #[inline] - fn from_into_handle(into_owned: Owned) -> Self + fn from_into_handle>(into_owned: Owned) -> Self where - Self: Sized, + Self: Sized + From, { - Self::from_handle(into_owned.into_handle()) + Self::from(into_owned.into()) } } @@ -206,20 +218,24 @@ pub trait FromHandle { #[cfg(windows)] pub trait FromSocket { /// Constructs a new instance of `Self` from the given socket. + #[deprecated( + since = "1.0.0", + note = "`FromSocket::from_socket` is replaced by `From::from`" + )] fn from_socket(owned: OwnedSocket) -> Self; /// Constructs a new instance of `Self` from the given socket converted /// from `into_owned`. #[inline] - fn from_into_socket(into_owned: Owned) -> Self + fn from_into_socket>(into_owned: Owned) -> Self where - Self: Sized, + Self: Sized + From, { - Self::from_socket(into_owned.into_socket()) + Self::from(into_owned.into()) } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] impl AsFd for &T { #[inline] @@ -228,7 +244,7 @@ impl AsFd for &T { } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(any(unix, target_os = "wasi"))] impl AsFd for &mut T { #[inline] @@ -237,7 +253,7 @@ impl AsFd for &mut T { } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] impl AsHandle for &T { #[inline] @@ -246,7 +262,7 @@ impl AsHandle for &T { } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] impl AsHandle for &mut T { #[inline] @@ -255,7 +271,7 @@ impl AsHandle for &mut T { } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] impl AsSocket for &T { #[inline] @@ -264,7 +280,7 @@ impl AsSocket for &T { } } -#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(io_safety_is_in_std))] #[cfg(windows)] impl AsSocket for &mut T { #[inline] diff --git a/vendor/io-lifetimes/src/types.rs b/vendor/io-lifetimes/src/types.rs index 695ae513c..7f7809fb0 100644 --- a/vendor/io-lifetimes/src/types.rs +++ b/vendor/io-lifetimes/src/types.rs @@ -50,12 +50,6 @@ const INVALID_SOCKET: usize = !0 as _; #[cfg(any(unix, target_os = "wasi"))] #[derive(Copy, Clone)] #[repr(transparent)] -#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] -// libstd/os/raw/mod.rs assures me that every libstd-supported platform has a -// 32-bit c_int. Below is -2, in two's complement, but that only works out -// because c_int is 32 bits. -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))] pub struct BorrowedFd<'fd> { fd: RawFd, _phantom: PhantomData<&'fd OwnedFd>, @@ -105,17 +99,6 @@ pub struct BorrowedHandle<'handle> { #[cfg(windows)] #[derive(Copy, Clone)] #[repr(transparent)] -#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] -// This is -2, in two's complement. -1 is `INVALID_SOCKET`. -#[cfg_attr( - all(rustc_attrs, target_pointer_width = "32"), - rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE) -)] -#[cfg_attr( - all(rustc_attrs, target_pointer_width = "64"), - rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) -)] pub struct BorrowedSocket<'socket> { socket: RawSocket, _phantom: PhantomData<&'socket OwnedSocket>, @@ -131,12 +114,6 @@ pub struct BorrowedSocket<'socket> { /// has the value `-1`. #[cfg(any(unix, target_os = "wasi"))] #[repr(transparent)] -#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] -// libstd/os/raw/mod.rs assures me that every libstd-supported platform has a -// 32-bit c_int. Below is -2, in two's complement, but that only works out -// because c_int is 32 bits. -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))] pub struct OwnedFd { fd: RawFd, } @@ -286,17 +263,6 @@ impl BorrowedHandle<'_> { /// [`INVALID_SOCKET`]. #[cfg(windows)] #[repr(transparent)] -#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] -#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] -// This is -2, in two's complement. -1 is `INVALID_SOCKET`. -#[cfg_attr( - all(rustc_attrs, target_pointer_width = "32"), - rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE) -)] -#[cfg_attr( - all(rustc_attrs, target_pointer_width = "64"), - rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) -)] pub struct OwnedSocket { socket: RawSocket, } diff --git a/vendor/io-lifetimes/src/views.rs b/vendor/io-lifetimes/src/views.rs index aec3750a0..b74a8c387 100644 --- a/vendor/io-lifetimes/src/views.rs +++ b/vendor/io-lifetimes/src/views.rs @@ -9,10 +9,14 @@ use crate::raw::{ AsRawFilelike, AsRawSocketlike, FromRawFilelike, FromRawSocketlike, IntoRawFilelike, IntoRawSocketlike, RawFilelike, RawSocketlike, }; +#[cfg(any(unix, target_os = "wasi"))] +use crate::OwnedFd; use crate::{ AsFilelike, AsSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike, OwnedFilelike, OwnedSocketlike, }; +#[cfg(windows)] +use crate::{OwnedHandle, OwnedSocket}; use std::fmt; use std::marker::PhantomData; use std::mem::ManuallyDrop; @@ -202,3 +206,72 @@ impl fmt::Debug for SocketlikeView<'_, Target> { .finish() } } + +#[cfg(any(unix, target_os = "wasi"))] +unsafe impl FilelikeViewType for OwnedFd {} +#[cfg(windows)] +unsafe impl FilelikeViewType for OwnedHandle {} +#[cfg(windows)] +unsafe impl SocketlikeViewType for OwnedSocket {} +unsafe impl FilelikeViewType for std::fs::File {} +unsafe impl SocketlikeViewType for std::net::TcpStream {} +unsafe impl SocketlikeViewType for std::net::TcpListener {} +unsafe impl SocketlikeViewType for std::net::UdpSocket {} +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixStream {} +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixListener {} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixDatagram {} +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "os_pipe")] +unsafe impl FilelikeViewType for os_pipe::PipeWriter {} +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "os_pipe")] +unsafe impl FilelikeViewType for os_pipe::PipeReader {} + +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "socket2")] +unsafe impl SocketlikeViewType for socket2::Socket {} + +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::net::TcpStream {} +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::net::TcpListener {} +#[cfg(not(target_os = "wasi"))] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::net::UdpSocket {} +#[cfg(unix)] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {} +#[cfg(unix)] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {} +#[cfg(unix)] +#[cfg(feature = "async_std")] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {} + +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::TcpStream {} +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::TcpListener {} +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::UdpSocket {} +#[cfg(unix)] +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::UnixDatagram {} +#[cfg(unix)] +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::UnixListener {} +#[cfg(unix)] +#[cfg(feature = "mio")] +unsafe impl SocketlikeViewType for mio::net::UnixStream {} +#[cfg(unix)] +#[cfg(feature = "mio")] +unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {} +#[cfg(unix)] +#[cfg(feature = "mio")] +unsafe impl FilelikeViewType for mio::unix::pipe::Sender {} -- cgit v1.2.3