Skip to content

Commit bfdc358

Browse files
committed
Auto merge of #29674 - inrustwetrust:flag_alignment, r=alexcrichton
The `enable-nonzeroing-move-hints` flag name was too long and caused misalignment of the help text. Now calculating the needed padding dynamically from the available flags instead.
2 parents 43b5d5e + 61bb652 commit bfdc358

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/librustc_driver/lib.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -657,24 +657,30 @@ Available lint options:
657657

658658
fn describe_debug_flags() {
659659
println!("\nAvailable debug options:\n");
660-
for &(name, _, opt_type_desc, desc) in config::DB_OPTIONS {
661-
let (width, extra) = match opt_type_desc {
662-
Some(..) => (21, "=val"),
663-
None => (25, "")
664-
};
665-
println!(" -Z {:>width$}{} -- {}", name.replace("_", "-"),
666-
extra, desc, width=width);
667-
}
660+
print_flag_list("-Z", config::DB_OPTIONS);
668661
}
669662

670663
fn describe_codegen_flags() {
671664
println!("\nAvailable codegen options:\n");
672-
for &(name, _, opt_type_desc, desc) in config::CG_OPTIONS {
665+
print_flag_list("-C", config::CG_OPTIONS);
666+
}
667+
668+
fn print_flag_list<T>(cmdline_opt: &str,
669+
flag_list: &[(&'static str, T, Option<&'static str>, &'static str)]) {
670+
let max_len = flag_list.iter().map(|&(name, _, opt_type_desc, _)| {
671+
let extra_len = match opt_type_desc {
672+
Some(..) => 4,
673+
None => 0
674+
};
675+
name.chars().count() + extra_len
676+
}).max().unwrap_or(0);
677+
678+
for &(name, _, opt_type_desc, desc) in flag_list {
673679
let (width, extra) = match opt_type_desc {
674-
Some(..) => (21, "=val"),
675-
None => (25, "")
680+
Some(..) => (max_len - 4, "=val"),
681+
None => (max_len, "")
676682
};
677-
println!(" -C {:>width$}{} -- {}", name.replace("_", "-"),
683+
println!(" {} {:>width$}{} -- {}", cmdline_opt, name.replace("_", "-"),
678684
extra, desc, width=width);
679685
}
680686
}

0 commit comments

Comments
 (0)