From dc63b7bb202819c712260cbbd9f9d21e976544e8 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Fri, 10 Apr 2026 20:10:42 +0200 Subject: [PATCH] cleanup: don't export write_loop twice Exporting it as both `safe_write_loop` and `write_loop` is redundant and causes inconsistencies. Remove the `pub use` and use `write_loop` for the function name. It is shorter, and in Rust the default assumption is that code is safe unless otherwise indicated, so there is no need to be explicit about it. Part of #12625 --- crates/common/src/lib.rs | 4 +--- src/tty_handoff.rs | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 031901b8e..960c3f9cf 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -213,7 +213,7 @@ fn read_to_end_interruptible(&mut self, buf: &mut Vec) -> std::io::Result<() /// A rusty port of the C++ `write_loop()` function from `common.cpp`. This should be deprecated in /// favor of native rust read/write methods at some point. -pub fn safe_write_loop(fd: &Fd, buf: &[u8]) -> std::io::Result<()> { +pub fn write_loop(fd: &Fd, buf: &[u8]) -> std::io::Result<()> { let fd = fd.as_raw_fd(); let mut total = 0; while total < buf.len() { @@ -232,8 +232,6 @@ pub fn safe_write_loop(fd: &Fd, buf: &[u8]) -> std::io::Result<()> Ok(()) } -pub use safe_write_loop as write_loop; - pub const fn help_section_exists(section: &str) -> bool { let haystack = include_str!("../../../share/help_sections"); let needle = section; diff --git a/src/tty_handoff.rs b/src/tty_handoff.rs index 88031c227..740d2eea4 100644 --- a/src/tty_handoff.rs +++ b/src/tty_handoff.rs @@ -17,7 +17,7 @@ }; use crate::threads::assert_is_main_thread; use crate::wutil::{perror_nix, wcstoi}; -use fish_common::{safe_write_loop, write_loop}; +use fish_common::write_loop; use fish_util::perror; use libc::{EINVAL, ENOTTY, EPERM, STDIN_FILENO, WNOHANG}; use nix::sys::termios::tcgetattr; @@ -336,7 +336,7 @@ pub fn safe_deactivate_tty_protocols() { let commands = protocols.safe_get_commands(false); // Safety: just writing data to stdout. - let _ = safe_write_loop(&libc::STDOUT_FILENO, commands); + let _ = write_loop(&libc::STDOUT_FILENO, commands); TTY_PROTOCOLS_ACTIVE.store(false, Ordering::Release); }