Skip to content

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

Open
@MarkMcCaskey

Description

@MarkMcCaskey
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

Activity

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on May 25, 2019
Centril

Centril commented on May 25, 2019

@Centril
Contributor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API 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

        Participants

        @Centril@estebank@MarkMcCaskey

        Issue actions

          cleaner output when dbg!() is given a literal value · Issue #61141 · rust-lang/rust