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

Cannot format variables named "display" or "debug" with tracing macros #2652

Closed
finnbear opened this issue Jul 14, 2023 · 2 comments
Closed

Comments

@finnbear
Copy link

Bug Report

Version

tracing 0.1.37 (latest)

Platform

Linux

Description

When porting from eprintln! to tracing::trace!, my use of the variable name display caused a compile error. I had to change it to to_display. I've tested and the same occurs for debug.

extern crate tracing;

fn main() {
    let display = String::from("message");
    tracing::trace!("{display}");
}
error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): `fn(_) -> DisplayValue<_> {display::<_>}` doesn't implement `std::fmt::Display`
 --> src/main.rs:5:22
  |
5 |     tracing::trace!("{display}");
  |                      ^^^^^^^^^ `fn(_) -> DisplayValue<_> {display::<_>}` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for fn item `fn(_) -> DisplayValue<_> {display::<_>}`
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
  = note: this error originates in the macro `format_args` which comes from the expansion of the macro `tracing::trace` (in Nightly builds, run with -Z macro-backtrace for more info)

Rust playground

@hawkw
Copy link
Member

hawkw commented Jul 14, 2023

See #2332 for some background on this unfortunate situation.

@finnbear
Copy link
Author

Thanks, closing as duplicate!

@finnbear finnbear closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2023
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