From 347cd4e6cb8a189c12a89e89a3951a5b1043308c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 8 Aug 2025 14:04:17 +1000 Subject: [PATCH 1/2] Augment the test. Some cases that are currently handled incorrectly. --- tests/ui/stats/macro-stats.rs | 30 ++++++++++++++++++++++++++---- tests/ui/stats/macro-stats.stderr | 7 ++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/tests/ui/stats/macro-stats.rs b/tests/ui/stats/macro-stats.rs index d986904ddd679..1b7d58bf0585c 100644 --- a/tests/ui/stats/macro-stats.rs +++ b/tests/ui/stats/macro-stats.rs @@ -49,10 +49,32 @@ fn opt(x: Option) { } } -macro_rules! long_name_that_fits_on_a_single_line { - () => {} -} -long_name_that_fits_on_a_single_line!(); +macro_rules! long_name_that_fits_on_one_line { () => {} } +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); +long_name_that_fits_on_one_line!(); + +macro_rules! long_name_that_fits_on_one_line_ { () => {} } +long_name_that_fits_on_one_line_!(); + +macro_rules! long_name_that_fits_on_one_line__ { () => {} } +long_name_that_fits_on_one_line__!(); + +macro_rules! long_name_that_fits_on_one_line___ { () => {} } +long_name_that_fits_on_one_line___!(); + +macro_rules! long_name_that_fits_on_one_line____ { () => {} } +long_name_that_fits_on_one_line____!(); + +macro_rules! long_name_that_fits_on_one_line_____ { () => {} } +long_name_that_fits_on_one_line_____!(); macro_rules! long_name_that_doesnt_fit_on_one_line { ($t:ty) => { diff --git a/tests/ui/stats/macro-stats.stderr b/tests/ui/stats/macro-stats.stderr index 8d0fdb8958a8d..0ef9adc6dd405 100644 --- a/tests/ui/stats/macro-stats.stderr +++ b/tests/ui/stats/macro-stats.stderr @@ -22,6 +22,11 @@ macro-stats trait_tys! 1 2 2.0 macro-stats n99! 2 2 1.0 4 2.0 macro-stats none! 1 1 1.0 4 4.0 macro-stats u32! 1 1 1.0 3 3.0 -macro-stats long_name_that_fits_on_a_single_line! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line! 10 10 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line_____! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line____! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line___! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line__! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line_! 1 1 1.0 0 0.0 macro-stats #[test] 1 1 1.0 0 0.0 macro-stats =================================================================================== From 0239e464876c8785e8601712220f17d9c58bcba6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 8 Aug 2025 14:10:54 +1000 Subject: [PATCH 2/2] Fix some bad formatting in `-Zmacro-stats` output. I also double-checked that everything looks good on some real-world crates. --- compiler/rustc_interface/src/passes.rs | 2 +- tests/ui/stats/macro-stats.stderr | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 8dec8069bc7bd..8bbd0e614921e 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -371,7 +371,7 @@ fn print_macro_stats(ecx: &ExtCtxt<'_>) { // 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 + uses_w -= name.len() - name_w; }; _ = writeln!( diff --git a/tests/ui/stats/macro-stats.stderr b/tests/ui/stats/macro-stats.stderr index 0ef9adc6dd405..75b90df6466ff 100644 --- a/tests/ui/stats/macro-stats.stderr +++ b/tests/ui/stats/macro-stats.stderr @@ -22,11 +22,11 @@ macro-stats trait_tys! 1 2 2.0 macro-stats n99! 2 2 1.0 4 2.0 macro-stats none! 1 1 1.0 4 4.0 macro-stats u32! 1 1 1.0 3 3.0 -macro-stats long_name_that_fits_on_one_line! 10 10 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line! 10 10 1.0 0 0.0 macro-stats long_name_that_fits_on_one_line_____! 1 1 1.0 0 0.0 -macro-stats long_name_that_fits_on_one_line____! 1 1 1.0 0 0.0 -macro-stats long_name_that_fits_on_one_line___! 1 1 1.0 0 0.0 -macro-stats long_name_that_fits_on_one_line__! 1 1 1.0 0 0.0 -macro-stats long_name_that_fits_on_one_line_! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line____! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line___! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line__! 1 1 1.0 0 0.0 +macro-stats long_name_that_fits_on_one_line_! 1 1 1.0 0 0.0 macro-stats #[test] 1 1 1.0 0 0.0 macro-stats ===================================================================================