tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.44k stars 717 forks source link

The `event!` macro in new `tracing` release makes clippy's `deref-addrof` lint unhappy #792

Open nagisa opened 4 years ago

nagisa commented 4 years ago

Bug Report

Version

tracing 0.1.16

Description

Clippy's deref-addrof lint is unhappy with uses of event! macro in the new tracing 0.1.16. It was fine in tracing 0.1.15.

use tracing::{event, Level};

fn banana(message: &str) {
    event!(Level::ERROR, %message);
}
[package]
name = "banana"
version = "0.1.0"
edition = "2018"

[dependencies]
tracing = { version = "=0.1.16", features = ["log-always"] }
$ cargo clippy -- -Dclippy::deref-addrof
    Updating crates.io index
    Checking banana v0.1.0 (/tmp/banana)
error: immediately dereferencing a reference
 --> src/lib.rs:4:5
  |
4 |     event!(Level::ERROR, %message);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: requested on the command line with `-D clippy::deref-addrof`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
nagisa commented 4 years ago

With -Zmacro-backtrace:

error: immediately dereferencing a reference
    --> /home/nagisa/.cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.16/src/macros.rs:2037:15
     |
531  |   / macro_rules! event {
532  |   |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({
533  |   |         {
534  |   |             $crate::__tracing_log!(
...      |
580  | / |             $crate::__tracing_log!(
581  | | |                 target: $target,
582  | | |                 $lvl,
583  | | |                 $($fields)*
584  | | |             );
     | |_|______________- in this macro invocation (#4)
...      |
724  | / |         $crate::event!(
725  | | |             target: module_path!(),
726  | | |             $lvl,
727  | | |             { %$($k).+, $($field)*}
728  | | |         )
     | |_|_________- in this macro invocation (#3)
...      |
734  |   |         $crate::event!($lvl, %$($k).+,)
     |   |         ------------------------------- in this macro invocation (#2)
...      |
741  |   |     );
742  |   | }
     |   | -
     |   | |
     |   | in this expansion of `event!` (#1)
     |   |_in this expansion of `$crate::event!` (#2)
     |     in this expansion of `$crate::event!` (#3)
...
2035 | /   macro_rules! level_to_log {
2036 | |       ($level:expr) => {
2037 | |           match *$level {
     | |                 ^^^^^^^
2038 | |               $crate::Level::ERROR => $crate::log::Level::Error,
...    |
2044 | |       };
2045 | |   }
     | |___- in this expansion of `$crate::level_to_log!` (#5)
...
2300 | /   macro_rules! __tracing_log {
2301 | |       (target: $target:expr, $level:expr, $($field:tt)+ ) => {
2302 | |           $crate::if_log_enabled! {{
2303 | |               use $crate::log;
2304 | |               let level = $crate::level_to_log!(&$level);
     | |                           ------------------------------ in this macro invocation (#5)
...    |
2322 | |       };
2323 | |   }
     | |___- in this expansion of `$crate::__tracing_log!` (#4)
     |
    ::: src/lib.rs:4:5
     |
4    |         event!(Level::ERROR, %message);
     |         ------------------------------- in this macro invocation (#1)
     |
     = note: requested on the command line with `-D clippy::deref-addrof`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
hawkw commented 4 years ago

@nagisa a couple questions:

nagisa commented 4 years ago

what version of clippy are you using?

I grabbed the current nightly toolchain just before reproducing. The version of clippy is:

clippy 0.0.212 (8aa18cb 2020-07-08)

is this specifically with event!, or does it occur with info!, debug!, etc as well?

Looks like just event!. This gives me a viable workaround.

hawkw commented 4 years ago

Looks like this occurs when the log feature is enabled. I believe it results from this change which, amusingly, was intended to fix a different clippy lint...