Skip to content

Fix some bad formatting in -Zmacro-stats output. #145082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
30 changes: 26 additions & 4 deletions tests/ui/stats/macro-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,32 @@ fn opt(x: Option<u32>) {
}
}

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 { () => {} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: How stable is it in extreme situations? Like(Maybe compiled successfully)

// compile-flags: -Zmacro-stats
mod a { pub mod b { pub mod c { pub mod d { pub mod e { pub mod f {
    #[macro_export]
    macro_rules! very_very_very_very_very_long_macro_name_that_is_really_long {
        () => {};
    }
}}}}}}
use crate::a::b::c::d::e::f::very_very_very_very_very_long_macro_name_that_is_really_long as m;
fn main() {
    m!(); m!(); m!();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to long_name_that_doesnt_fit_on_one_line: the numbers are put on the following 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) => {
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/stats/macro-stats.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===================================================================================
Loading