Skip to content

Change AsFd::as_fd etc. from &self to self. #93869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl fmt::Debug for OwnedFd {
/// call the method. Windows platforms have a corresponding `AsHandle` and
/// `AsSocket` set of traits.
#[unstable(feature = "io_safety", issue = "87074")]
pub trait AsFd {
pub trait AsFd<'a> {
/// Borrows the file descriptor.
///
/// # Example
Expand All @@ -197,21 +197,21 @@ pub trait AsFd {
/// # Ok::<(), io::Error>(())
/// ```
#[unstable(feature = "io_safety", issue = "87074")]
fn as_fd(&self) -> BorrowedFd<'_>;
fn as_fd(self) -> BorrowedFd<'a>;
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for BorrowedFd<'_> {
impl<'a> AsFd<'a> for &'a BorrowedFd<'_> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
*self
}
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for OwnedFd {
impl<'a> AsFd<'a> for &'a OwnedFd {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
// Safety: `OwnedFd` and `BorrowedFd` have the same validity
// invariants, and the `BorrowdFd` is bounded by the lifetime
// of `&self`.
Expand All @@ -220,9 +220,9 @@ impl AsFd for OwnedFd {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for fs::File {
impl<'a> AsFd<'a> for &'a fs::File {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().as_fd()
}
}
Expand All @@ -244,9 +244,9 @@ impl From<OwnedFd> for fs::File {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::net::TcpStream {
impl<'a> AsFd<'a> for &'a crate::net::TcpStream {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().socket().as_fd()
}
}
Expand All @@ -270,9 +270,9 @@ impl From<OwnedFd> for crate::net::TcpStream {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::net::TcpListener {
impl<'a> AsFd<'a> for &'a crate::net::TcpListener {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().socket().as_fd()
}
}
Expand All @@ -296,9 +296,9 @@ impl From<OwnedFd> for crate::net::TcpListener {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::net::UdpSocket {
impl<'a> AsFd<'a> for &'a crate::net::UdpSocket {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().socket().as_fd()
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ impl IntoRawFd for PidFd {
}
}

impl AsFd for PidFd {
fn as_fd(&self) -> BorrowedFd<'_> {
impl<'a> AsFd<'a> for &'a PidFd {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().as_fd()
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,12 +966,12 @@ pub fn chown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io::
///
/// fn main() -> std::io::Result<()> {
/// let f = std::fs::File::open("/file")?;
/// fs::fchown(f, Some(0), Some(0))?;
/// fs::fchown(&f, Some(0), Some(0))?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "unix_chown", issue = "88989")]
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
pub fn fchown<'a, F: AsFd<'a>>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
sys::fs::fchown(fd.as_fd().as_raw_fd(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX))
}

Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/net/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,9 @@ impl IntoRawFd for UnixDatagram {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for UnixDatagram {
impl<'a> AsFd<'a> for &'a UnixDatagram {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.0.as_inner().as_fd()
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ impl IntoRawFd for UnixListener {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for UnixListener {
impl<'a> AsFd<'a> for &'a UnixListener {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.0.as_inner().as_fd()
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ impl IntoRawFd for UnixStream {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for UnixStream {
impl<'a> AsFd<'a> for &'a UnixStream {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.0.as_fd()
}
}
Expand Down
12 changes: 6 additions & 6 deletions library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ impl IntoRawFd for process::ChildStderr {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::process::ChildStdin {
impl<'a> AsFd<'a> for &'a crate::process::ChildStdin {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().as_fd()
}
}
Expand All @@ -404,9 +404,9 @@ impl From<crate::process::ChildStdin> for OwnedFd {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::process::ChildStdout {
impl<'a> AsFd<'a> for &'a crate::process::ChildStdout {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().as_fd()
}
}
Expand All @@ -420,9 +420,9 @@ impl From<crate::process::ChildStdout> for OwnedFd {
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for crate::process::ChildStderr {
impl<'a> AsFd<'a> for &'a crate::process::ChildStderr {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
fn as_fd(self) -> BorrowedFd<'a> {
self.as_inner().as_fd()
}
}
Expand Down
56 changes: 28 additions & 28 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl fmt::Debug for OwnedHandle {

/// A trait to borrow the handle from an underlying object.
#[unstable(feature = "io_safety", issue = "87074")]
pub trait AsHandle {
pub trait AsHandle<'a> {
/// Borrows the handle.
///
/// # Example
Expand All @@ -313,29 +313,29 @@ pub trait AsHandle {
/// let borrowed_handle: BorrowedHandle<'_> = f.as_handle();
/// # Ok::<(), io::Error>(())
/// ```
fn as_handle(&self) -> BorrowedHandle<'_>;
fn as_handle(self) -> BorrowedHandle<'a>;
}

impl AsHandle for BorrowedHandle<'_> {
impl<'a> AsHandle<'a> for &'a BorrowedHandle<'_> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
*self
}
}

impl AsHandle for OwnedHandle {
impl<'a> AsHandle<'a> for &'a OwnedHandle {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
// Safety: `OwnedHandle` and `BorrowedHandle` have the same validity
// invariants, and the `BorrowdHandle` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl AsHandle for fs::File {
impl<'a> AsHandle<'a> for &'a fs::File {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
self.as_inner().as_handle()
}
}
Expand All @@ -354,51 +354,51 @@ impl From<OwnedHandle> for fs::File {
}
}

impl AsHandle for crate::io::Stdin {
impl<'a> AsHandle<'a> for &'a crate::io::Stdin {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl<'a> AsHandle for crate::io::StdinLock<'a> {
impl<'a, 'b> AsHandle<'a> for &'a crate::io::StdinLock<'b> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl AsHandle for crate::io::Stdout {
impl<'a> AsHandle<'a> for &'a crate::io::Stdout {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl<'a> AsHandle for crate::io::StdoutLock<'a> {
impl<'a, 'b> AsHandle<'a> for &'a crate::io::StdoutLock<'b> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl AsHandle for crate::io::Stderr {
impl<'a> AsHandle<'a> for &'a crate::io::Stderr {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl<'a> AsHandle for crate::io::StderrLock<'a> {
impl<'a, 'b> AsHandle<'a> for &'a crate::io::StderrLock<'b> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}

impl AsHandle for crate::process::ChildStdin {
impl<'a> AsHandle<'a> for &'a crate::process::ChildStdin {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}
Expand All @@ -410,9 +410,9 @@ impl From<crate::process::ChildStdin> for OwnedHandle {
}
}

impl AsHandle for crate::process::ChildStdout {
impl<'a> AsHandle<'a> for &'a crate::process::ChildStdout {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}
Expand All @@ -424,9 +424,9 @@ impl From<crate::process::ChildStdout> for OwnedHandle {
}
}

impl AsHandle for crate::process::ChildStderr {
impl<'a> AsHandle<'a> for &'a crate::process::ChildStderr {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}
Expand All @@ -438,9 +438,9 @@ impl From<crate::process::ChildStderr> for OwnedHandle {
}
}

impl<T> AsHandle for crate::thread::JoinHandle<T> {
impl<'a, T> AsHandle<'a> for &'a crate::thread::JoinHandle<T> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
fn as_handle(self) -> BorrowedHandle<'a> {
unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) }
}
}
Expand Down
24 changes: 12 additions & 12 deletions library/std/src/os/windows/io/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,31 +205,31 @@ impl fmt::Debug for OwnedSocket {

/// A trait to borrow the socket from an underlying object.
#[unstable(feature = "io_safety", issue = "87074")]
pub trait AsSocket {
pub trait AsSocket<'a> {
/// Borrows the socket.
fn as_socket(&self) -> BorrowedSocket<'_>;
fn as_socket(self) -> BorrowedSocket<'a>;
}

impl AsSocket for BorrowedSocket<'_> {
impl<'a> AsSocket<'a> for &'a BorrowedSocket<'_> {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
fn as_socket(self) -> BorrowedSocket<'a> {
*self
}
}

impl AsSocket for OwnedSocket {
impl<'a> AsSocket<'a> for &'a OwnedSocket {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
fn as_socket(self) -> BorrowedSocket<'a> {
// Safety: `OwnedSocket` and `BorrowedSocket` have the same validity
// invariants, and the `BorrowdSocket` is bounded by the lifetime
// of `&self`.
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
}
}

impl AsSocket for crate::net::TcpStream {
impl<'a> AsSocket<'a> for &'a crate::net::TcpStream {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
fn as_socket(self) -> BorrowedSocket<'a> {
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
}
}
Expand All @@ -248,9 +248,9 @@ impl From<OwnedSocket> for crate::net::TcpStream {
}
}

impl AsSocket for crate::net::TcpListener {
impl<'a> AsSocket<'a> for &'a crate::net::TcpListener {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
fn as_socket(self) -> BorrowedSocket<'a> {
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
}
}
Expand All @@ -269,9 +269,9 @@ impl From<OwnedSocket> for crate::net::TcpListener {
}
}

impl AsSocket for crate::net::UdpSocket {
impl<'a> AsSocket<'a> for &'a crate::net::UdpSocket {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
fn as_socket(self) -> BorrowedSocket<'a> {
unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
}
}
Expand Down
Loading