diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-06-30 20:49:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 20:49:43 +0200 |
| commit | 172fc60e5f5ef1b2dc16bf1181bc8fc993ebabbe (patch) | |
| tree | e141720a69c0aaddd79106a9f76e478ae5fe184d /compiler/rustc_interface | |
| parent | d3c02b48df5c0ae8a447168589605e6a6c6daabc (diff) | |
| parent | e0761a57ab41d213a705c0cc005d93a3463399c6 (diff) | |
| download | rust-172fc60e5f5ef1b2dc16bf1181bc8fc993ebabbe.tar.gz rust-172fc60e5f5ef1b2dc16bf1181bc8fc993ebabbe.zip | |
Rollup merge of #143223 - nnethercote:improve-macro-stats-printing, r=petrochenkov
Improve macro stats printing Fix a small formatting issue that has been annoying me. r? ``@petrochenkov``
Diffstat (limited to 'compiler/rustc_interface')
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index edfb05e2ccd..b4bd2f2ca24 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -341,20 +341,30 @@ fn print_macro_stats(ecx: &ExtCtxt<'_>) { } for (bytes, lines, uses, name, kind) in macro_stats { let mut name = ExpnKind::Macro(kind, *name).descr(); + let uses_with_underscores = thousands::usize_with_underscores(uses); let avg_lines = lines as f64 / uses as f64; let avg_bytes = bytes as f64 / uses as f64; - if name.len() >= name_w { - // If the name is long, print it on a line by itself, then - // set the name to empty and print things normally, to show the - // stats on the next line. + + // Ensure the "Macro Name" and "Uses" columns are as compact as possible. + let mut uses_w = uses_w; + if name.len() + uses_with_underscores.len() >= name_w + uses_w { + // The name would abut or overlap the uses value. Print the name + // on a line by itself, then set the name to empty and print things + // normally, to show the stats on the next line. _ = writeln!(s, "{prefix} {:<name_w$}", name); name = String::new(); - } + } else if name.len() >= name_w { + // The name won't abut or overlap with the uses value, but it does + // overlap with the empty part of the uses column. Shrink the width + // of the uses column to account for the excess name length. + uses_w = uses_with_underscores.len() + 1 + }; + _ = writeln!( s, "{prefix} {:<name_w$}{:>uses_w$}{:>lines_w$}{:>avg_lines_w$}{:>bytes_w$}{:>avg_bytes_w$}", name, - thousands::usize_with_underscores(uses), + uses_with_underscores, thousands::usize_with_underscores(lines), thousands::f64p1_with_underscores(avg_lines), thousands::usize_with_underscores(bytes), |
