Skip to content

Cleaner dbg! macro without alternate formatting #115589

@rsalmei

Description

@rsalmei

Hello!
I have to say I don't love the dbg! macro. It pollutes the output unnecessarily, and could easily be way cleaner.
Personally, I think it is a missed opportunity. It actually doesn't use debug formatting {:?}, it uses alternate debugging {:#?} I'm not sure why. This, unfortunately, makes everything get a lot more newlines than needed. So, we get this:

[src/lib.rs:105] &order = [
    8,
    14,
    13,
]
[src/lib.rs:105] &order = [
    6,
    14,
    5,
    4,
    3,
    2,
]
[src/lib.rs:9] &win = [
    8,
    14,
    13,
]

instead of simply this:

[src/lib.rs:105] &order = [8, 14, 13]
[src/lib.rs:105] &order = [6, 14, 5, 4, 3, 2]
[src/lib.rs:9] &win = [8, 14, 13]

Similarly, for structs it prints one field per line and gets very verbose.

I imagine people use the alternate formatting very sparingly, only when something gets so complex that it warrants the added pollution, I know I rarely have used it. In the vast majority of cases, we all use {:?} the standard debug formatting. So, why adopt the alternate one in the dbg! macro?

I'd like to ask you to please reconsider it. It is a single character change.
Thank you.

$crate::eprintln!("[{}:{}] {} = {:#?}",
$crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp);

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions