Skip to content

Using debug as an argument in trace!, debug!, warn!, info!, or error! produces a compile error: error[E0277]: fn(_) -> DebugValue<_> {debug::<_>} doesn't implement Debug #3381

@sampathsris

Description

@sampathsris

Bug Report

Version

v0.1.41

Platform

Linux <redacted> 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Description

There seems to be a sanitation bug in tracing macros, which produces a compile error if you use debug as one of argument names for string interpolation:

fn main() {
    let debug = false;
    tracing::trace!("debug: {debug:?}");
    tracing::debug!("debug: {debug:?}");
    tracing::warn!("debug:  {debug:?}");
    tracing::info!("debug:  {debug:?}");
    tracing::error!("debug: {debug:?}");
}

This should compile without errors, but we get:

error[E0277]: `fn(_) -> DebugValue<_> {debug::<_>}` doesn't implement `Debug`
 --> tracing_bug/src/main.rs:3:30
  |
3 |     tracing::trace!("debug: {debug:?}");
  |                             -^^^^^---
  |                             ||
  |                             |`fn(_) -> DebugValue<_> {debug::<_>}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
  |                             required by this formatting parameter
  |

(Error help and other similar error messages omitted for brevity).

Notes:

  • The issue does not happen if the argument ident is trace, warn, info, or error.
    let trace = false;
    tracing::trace!("debug: {trace:?}");  // compiles
    
    let warn = false;
    tracing::trace!("debug: {warn:?}");  // compiles
    
    let info = false;
    tracing::trace!("debug: {info:?}");  // compiles
    
    let error = false;
    tracing::trace!("debug: {error:?}");  // compiles
  • Other macros may be affected, but I have not exhaustively tested it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions