-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Cleaner dbg! macro without alternate formatting #115589
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
Comments
+1, I think the I looked around a little for prior proposals to see if this seems like to be accepted or has been asked before. FWIW — the RFC for It seems that A couple relevant comments in that original discussion: rust-lang/libs-team#125 (for #103334) seems like a related ACP although it seems to focus mainly on stripping out the file/line number, which isn't quite the same as this request... Something occurred to me as a possible enhancement for cases where dbg!(x); // prints with {:?} format
dbg!(#x); // prints with {:#?} format (current behavior of `dbg!(x)`) A quick mockup of that: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b9276544d7d61cea1d7cd08ffe233a54 The newer (accepted) RFC2361 specifically wanted to avoid giving users control over the output, probably because it could easily invite a much longer discussion about what's supported ("why not padding?" "why not support the whole This kind of thing could easily be implemented as a crate, or in fact users could opt to install the original RFC2173 implementation! https://crates.io/crates/dbg However I think a big part of the value of the So, in summary, these seem like the likely/possible outcomes - but probably would need the libs team to make a call as well here:
|
Thank you very much for your considerations!
I loved this suggestion and its impl! I think it would nicely fix it for almost everybody 👏 |
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:instead of simply this:
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 thedbg!
macro?I'd like to ask you to please reconsider it. It is a single character change.
Thank you.
rust/library/std/src/macros.rs
Lines 365 to 366 in 25283f4
The text was updated successfully, but these errors were encountered: