Skip to content
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

cleaner output when dbg!() is given a literal value #61141

Open
MarkMcCaskey opened this issue May 24, 2019 · 1 comment
Open

cleaner output when dbg!() is given a literal value #61141

MarkMcCaskey opened this issue May 24, 2019 · 1 comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@MarkMcCaskey
Copy link
Contributor

Hello! I'm unsure if this should be an RFC but it seems similar to #57845, so I'll start by filing an issue here.

The problem

Often I end up writing dbg! code with constant values, usually strings, to trace control flow.

dbg!("Start loop");
while condition {
   dbg!("Phase 1");
   unsafe { libc::do_something() }
   ...
   dbg!("Phase 2");
   ...
}

The output is a bit noisier than I'd like.
[lib/emscripten/src/syscalls/unix.rs:826] "Start loop" = "Start loop"

The solution

Detect if the argument to the macro is a literal value (assuming this is possible) and make the output just:
[lib/emscripten/src/syscalls/unix.rs:826] "Start loop"

Alternatives considered:

  • eprintln!: doesn't have line and file info. It's a separate macro, so it's less aesthetically pleasing and less intuitive in my opinion.
  • debug!: usually I'm already using these for other tasks and filtering them out is harder and less convenient than dbg!; dbg! is nice because it's explicitly a temporary debugging tool
  • a custom macro: it'd be nice to be able to use this consistently anywhere
@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 25, 2019
@Centril
Copy link
Contributor

Centril commented May 25, 2019

This was discussed in https://github.com/rust-lang/rfcs/blob/master/text/2361-dbg-macro.md#outputting-lit--lit-for-dbglit-instead-of-lit.

assuming this is possible

It is, with literal as the matcher, but it becomes hairy with multiple arguments.

Alternatives considered:

  1. Use dbg!() with no arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants