Skip to content

Commit 59cfee1

Browse files
committed
refactor(cli): remove allocation and use format arg capture
1 parent 8fee74d commit 59cfee1

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/bin/cargo/cli.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,28 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
6161
let reset = anstyle::Reset.render();
6262

6363
let options = CliUnstable::help();
64-
let non_hidden_options: Vec<(String, String)> = options
65-
.iter()
66-
.filter(|(_, help_message)| *help_message != HIDDEN)
67-
.map(|(name, help)| (name.to_string(), help.to_string()))
68-
.collect();
69-
let longest_option = non_hidden_options
64+
let max_length = options
7065
.iter()
66+
.filter(|(_, help)| *help != HIDDEN)
7167
.map(|(option_name, _)| option_name.len())
7268
.max()
7369
.unwrap_or(0);
74-
let help_lines: Vec<String> = non_hidden_options
70+
let z_flags = options
7571
.iter()
76-
.map(|(option_name, option_help_message)| {
77-
let option_name_kebab_case = option_name.replace("_", "-");
78-
format!(
79-
" {literal}-Z {:<longest_option$}{reset} {}",
80-
option_name_kebab_case, option_help_message
81-
)
72+
.filter(|(_, help)| *help != HIDDEN)
73+
.map(|(opt, help)| {
74+
let opt = opt.replace("_", "-");
75+
format!(" {literal}-Z {opt:<max_length$}{reset} {help}")
8276
})
83-
.collect();
84-
let joined = help_lines.join("\n");
77+
.join("\n");
8578
drop_println!(
8679
config,
8780
"\
8881
{header}Available unstable (nightly-only) flags:{reset}
8982
90-
{}
83+
{z_flags}
9184
9285
Run with `{literal}cargo -Z{reset} {placeholder}[FLAG] [COMMAND]{reset}`",
93-
joined
9486
);
9587
if !config.nightly_features_allowed {
9688
drop_println!(

0 commit comments

Comments
 (0)