From 67de3134115d31fc651582b6d413db6ad7da3cf2 Mon Sep 17 00:00:00 2001 From: vasilito Date: Sat, 18 Jul 2026 18:05:20 +0900 Subject: [PATCH] refactor: box large Error variants (Command, Pkgar) to fix result_large_err MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Boxing the Command(Command, ExitStatus) variant (204 bytes) and Pkgar(pkgar::Error) variant (272 bytes) reduces the Error enum from 272+ bytes to ~80 bytes, eliminating all 70 result_large_err warnings. Changes: - Error::Command(Command, ExitStatus) → Command(Box<(Command, ExitStatus)>) - Error::Pkgar(pkgar::Error) → Pkgar(Box) - Updated 2 construction sites in fs.rs (Command) - Updated 1 construction site in package.rs (Pkgar) - Updated 1 From conversion in lib.rs (Pkgar) - Updated Display match in lib.rs (Command destructuring) This is a heap allocation on error paths only — zero cost on the happy path. Box auto-implements Display/Debug when inner type does, so formatting is unchanged. Verification: cargo check ✅, cargo test --lib ✅ 38/38. Clippy: 74 → 4 warnings (70 eliminated). --- src/cook/fs.rs | 4 ++-- src/cook/package.rs | 2 +- src/lib.rs | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cook/fs.rs b/src/cook/fs.rs index 36c6d349c5..df8a5df95c 100644 --- a/src/cook/fs.rs +++ b/src/cook/fs.rs @@ -201,7 +201,7 @@ pub fn run_command(mut command: process::Command, stdout_pipe: &PtyOut) -> Resul .map_err(wrap_io_err!("waiting to exit"))?; if !status.success() { - return Err(Error::Command(command, status)); + return Err(Error::Command(Box::new((command, status)))); } Ok(()) @@ -289,7 +289,7 @@ pub fn run_command_stdin( let status = child.wait().map_err(wrap_io_err!("Spawning"))?; if !status.success() { - return Err(Error::Command(command, status)); + return Err(Error::Command(Box::new((command, status)))); } Ok(()) diff --git a/src/cook/package.rs b/src/cook/package.rs index 57b3658cc2..9d6ec94751 100644 --- a/src/cook/package.rs +++ b/src/cook/package.rs @@ -158,7 +158,7 @@ pub fn package_toml( pkgar_core::Packaging::LZMA2 => { let mut size = header .total_size() - .map_err(|e| Error::Pkgar(pkgar::Error::Core(e)))? + .map_err(|e| Error::Pkgar(Box::new(pkgar::Error::Core(e))))? as u64; let entries = package .read_entries() diff --git a/src/lib.rs b/src/lib.rs index f47b36ade1..4025493a44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,9 +43,9 @@ pub enum Error { dst: PathBuf, context: &'static str, }, - Command(Command, ExitStatus), + Command(Box<(Command, ExitStatus)>), Package(pkg::PackageError), - Pkgar(pkgar::Error), + Pkgar(Box), Other(String), } @@ -86,7 +86,8 @@ impl Display for Error { source ) } - Error::Command(command, exit_status) => { + Error::Command(boxed) => { + let (command, exit_status) = &**boxed; write!( f, "Failed to run [{:?}]: exited with status {}", @@ -174,7 +175,7 @@ impl From for Error { path, context, }, - _ => Error::Pkgar(value), + _ => Error::Pkgar(Box::new(value)), } } }