From cbfb4da9f3f9d8424da59542474d41027554e595 Mon Sep 17 00:00:00 2001 From: oech3 <> Date: Tue, 9 Jun 2026 18:56:51 +0900 Subject: [PATCH] wc: remove unnecessary .as_fd() --- src/uu/wc/src/count_fast.rs | 9 +++------ src/uu/wc/src/wc.rs | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index 7e8aef5ed..c4281eac2 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -12,8 +12,6 @@ use std::io::{self, ErrorKind, Read}; #[cfg(unix)] use std::io::{Seek, SeekFrom}; -#[cfg(unix)] -use std::os::fd::{AsFd, AsRawFd}; #[cfg(windows)] use std::os::windows::fs::MetadataExt; #[cfg(windows)] @@ -30,7 +28,7 @@ const BUF_SIZE: usize = 64 * 1024; /// caller will fall back to a simpler method. #[inline] #[cfg(any(target_os = "linux", target_os = "android"))] -fn count_bytes_using_splice(fd: &impl AsFd) -> Result { +fn count_bytes_using_splice(fd: &impl rustix::fd::AsFd) -> Result { use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe, splice}; let null_file = uucore::pipes::dev_null().ok_or(0_usize)?; let mut byte_count = 0; @@ -69,8 +67,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti #[cfg(unix)] { - let fd = handle.as_fd(); - if let Ok(stat) = rustix::fs::fstat(fd) { + if let Ok(stat) = rustix::fs::fstat(&handle) { // If the file is regular, then the `st_size` should hold // the file's size in bytes. // If stat.st_size = 0 then @@ -109,7 +106,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti // However, the raw file descriptor in this situation would be equal to `0` // for STDIN in both invocations. // Therefore we cannot rely of `st_size` here and should fall back on full read. - if fd.as_raw_fd() > 0 + if handle.as_raw_fd() > 0 && (stat.st_mode as libc::mode_t & libc::S_IFREG) != 0 && stat.st_size > 0 { diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 8b6b8dc41..a7fea0519 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -298,10 +298,8 @@ impl<'a> Input<'a> { #[cfg(unix)] fn is_stdin_small_file() -> bool { - use std::os::fd::AsFd; - matches!( - rustix::fs::fstat(io::stdin().as_fd()), + rustix::fs::fstat(io::stdin()), Ok(meta) if meta.st_mode as libc::mode_t & libc::S_IFMT == libc::S_IFREG && meta.st_size <= (10 << 20) ) }