From 4b3b21554ce9e61f10356e5c06671b704ecc52ab Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 22 Sep 2026 09:32:55 +0100 Subject: [PATCH 1/2] style: reorder attributes and documentation comments --- src/uucore/src/lib/mods/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 146f973f503..14215bd91b7 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -340,8 +340,8 @@ pub struct UUsageError { } impl UUsageError { - #[allow(clippy::new_ret_no_self)] /// Create a new `UUsageError` with a given exit code and message. + #[allow(clippy::new_ret_no_self)] pub fn new>(code: i32, message: S) -> Box { Box::new(Self { code, @@ -401,8 +401,8 @@ pub struct UIoError { } impl UIoError { - #[allow(clippy::new_ret_no_self)] /// Create a new `UIoError` with a given exit code and message. + #[allow(clippy::new_ret_no_self)] pub fn new>(kind: std::io::ErrorKind, context: S) -> Box { Box::new(Self { context: Some(context.into()), @@ -696,8 +696,8 @@ macro_rules! uio_error( pub struct ExitCode(pub i32); impl ExitCode { - #[allow(clippy::new_ret_no_self)] /// Create a new `ExitCode` with a given exit code. + #[allow(clippy::new_ret_no_self)] pub fn new(code: i32) -> Box { Box::new(Self(code)) } From 1d5c49a6d5d9b67838a714e5b6c3efad457cb334 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 22 Sep 2026 00:25:56 +0100 Subject: [PATCH 2/2] perf: mark error handling functions as cold and non-inlineable Error construction is infrequently executed compared with the normal success paths. Mark these functions with `#[cold]` so the compiler can treat them as unlikely code paths and keep cold code separate from hot code. Use `#[inline(never)]` to prevent error-handling code from being inlined into their callers, avoiding unnecessary code-size growth and keeping the normal execution paths smaller. --- src/uu/dd/src/diagnostics.rs | 2 ++ src/uu/df/src/df.rs | 2 ++ src/uu/env/src/env.rs | 2 ++ src/uu/sort/src/sort.rs | 2 ++ src/uu/stat/src/stat.rs | 2 ++ src/uu/uniq/src/uniq.rs | 2 ++ src/uucore/src/lib/mods/error.rs | 6 ++++++ 7 files changed, 18 insertions(+) diff --git a/src/uu/dd/src/diagnostics.rs b/src/uu/dd/src/diagnostics.rs index 7b10be5953f..e38ab3226bb 100644 --- a/src/uu/dd/src/diagnostics.rs +++ b/src/uu/dd/src/diagnostics.rs @@ -32,6 +32,8 @@ use crate::parseargs::ParseError; /// when they were not kept. /// * `operand` - The `KEY=VALUE` operand at fault, as typed. /// * `error` - What the parser made of it. +#[cold] +#[inline(never)] pub fn operand_error( diag_args: Option<&[OsString]>, operand: &str, diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index b0494359cda..022b61d1196 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -169,6 +169,8 @@ enum OptionsError { /// * `error` - What the size parser rejected the value with. /// * `matches` - The parsed command line, for the value as it was typed. /// * `diag_args` - The arguments as typed, or `None` when they were not kept. +#[cold] +#[inline(never)] fn block_size_error( error: &ParseSizeError, matches: &ArgMatches, diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index b6d2018ebe9..e486a7fce81 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -555,6 +555,8 @@ struct ParsedArguments { } impl EnvAppData { + #[cold] + #[inline(never)] fn make_error_no_such_file_or_dir(&self, prog: &OsStr) -> Box { uucore::show_error!( "{}", diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 03f47e15707..ae2e144913c 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -657,6 +657,8 @@ fn incompatible_options_message(opts: &str) -> String { ) } +#[cold] +#[inline(never)] fn incompatible_options_error(opts: &str) -> Box { USimpleError::new(2, incompatible_options_message(opts)) } diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index c030437f656..41fe5bf895c 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -138,6 +138,8 @@ impl DirectiveError { /// * `option` - The format as typed and the option it was given to, or /// `None` for a format stat built itself, which is not on the command /// line and has nothing to point at. + #[cold] + #[inline(never)] fn to_error( &self, diag_args: Option<&[OsString]>, diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 767b66b18df..34c0c04b5b7 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -630,6 +630,8 @@ fn handle_extract_obs_skip_chars( /// Unfortunately these overrides are necessary, since several GNU tests /// for `uniq` hardcode and require the exact wording of the error message /// and it is not compatible with how Clap formats and displays those error messages. +#[cold] +#[inline(never)] fn map_clap_errors(clap_error: Error) -> Box { let footer = translate!("uniq-error-try-help"); let override_arg_conflict = translate!("uniq-error-group-mutually-exclusive") + "\n" + &footer; diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 14215bd91b7..ca55ef97f6c 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -306,6 +306,8 @@ pub struct USimpleError { impl USimpleError { /// Create a new `USimpleError` with a given exit code and message. + #[cold] + #[inline(never)] #[allow(clippy::new_ret_no_self)] pub fn new>(code: i32, message: S) -> Box { Box::new(Self { @@ -341,6 +343,8 @@ pub struct UUsageError { impl UUsageError { /// Create a new `UUsageError` with a given exit code and message. + #[cold] + #[inline(never)] #[allow(clippy::new_ret_no_self)] pub fn new>(code: i32, message: S) -> Box { Box::new(Self { @@ -697,6 +701,8 @@ pub struct ExitCode(pub i32); impl ExitCode { /// Create a new `ExitCode` with a given exit code. + #[cold] + #[inline(never)] #[allow(clippy::new_ret_no_self)] pub fn new(code: i32) -> Box { Box::new(Self(code))