From 811312cc61cd7c673cb0965d4f3669ba4b0bf3d7 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 8 Jan 2024 20:37:14 -0500 Subject: [PATCH] refactor(cli): remove allocation and use format arg capture --- src/bin/cargo/cli.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index cefa971a6c71..966f8d0280c4 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -61,36 +61,27 @@ pub fn main(config: &mut LazyConfig) -> CliResult { let reset = anstyle::Reset.render(); let options = CliUnstable::help(); - let non_hidden_options: Vec<(String, String)> = options - .iter() - .filter(|(_, help_message)| *help_message != HIDDEN) - .map(|(name, help)| (name.to_string(), help.to_string())) - .collect(); - let longest_option = non_hidden_options + let max_length = options .iter() .map(|(option_name, _)| option_name.len()) .max() - .unwrap_or(0); - let help_lines: Vec = non_hidden_options + .unwrap(); + let z_flags = options .iter() - .map(|(option_name, option_help_message)| { - let option_name_kebab_case = option_name.replace("_", "-"); - format!( - " {literal}-Z {: