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

#[instrument] breaks compilation of functions with argument named debug or display #1318

Open
sersorrel opened this issue Mar 22, 2021 · 1 comment

Comments

@sersorrel
Copy link

sersorrel commented Mar 22, 2021

Bug Report

Version

│   │   ├── tracing-core v0.1.17
│   │   └── tracing-error v0.1.2
│   │       ├── tracing v0.1.22
│   │       │   ├── tracing-attributes v0.1.11 (proc-macro)
│   │       │   └── tracing-core v0.1.17 (*)
│   │       └── tracing-subscriber v0.2.15
│   │           └── tracing-core v0.1.17 (*)
│   └── tracing-error v0.1.2 (*)
└── tracing v0.1.22 (*)

Platform

Linux what 4.15.0-139-generic #143-Ubuntu SMP Tue Mar 16 01:30:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Description

Trying to #[instrument] a function which takes a debug or display parameter causes a compilation error.

For example, this:

use tracing::instrument;

#[instrument]
fn foo(display: ()) {
    println!("{:?}", display);
}

fn main() {
    foo(());
}

results in the following error:

error[E0277]: `fn(_) -> DisplayValue<_> {display::<_>}` doesn't implement `Debug`
   --> src/main.rs:3:1
    |
3   | #[instrument]
    | ^^^^^^^^^^^^^ `fn(_) -> DisplayValue<_> {display::<_>}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    | 
   ::: /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/tracing-core-0.1.17/src/field.rs:266:8
    |
266 |     T: fmt::Debug,
    |        ---------- required by this bound in `debug`
    |
    = help: the trait `Debug` is not implemented for `fn(_) -> DisplayValue<_> {display::<_>}`
    = note: required because of the requirements on the impl of `Debug` for `&fn(_) -> DisplayValue<_> {display::<_>}`
    = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

(playground link)

Possibly related: #805

@sersorrel sersorrel changed the title #[instrument] breaks compilation of functions with argument named display #[instrument] breaks compilation of functions with argument named debug or display Mar 23, 2021
@hawkw
Copy link
Member

hawkw commented Jul 14, 2023

See also #2332.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants