Skip to content

Commit

Permalink
macros: Fix missing field prefixes (#2878)
Browse files Browse the repository at this point in the history
## Motivation

In the simple macro cases with e.g. only "name" or only "target" these
prefixes exist, but for the more complicated cases like "name + target"
the prefixes were not piped through and silently ignored. This led to
the compiler complaining about `Value` not being implemented despite the
usage of the `?` or `%` prefixes:

<img width="1056" alt="Bildschirmfoto 2024-02-14 um 12 38 00"
src="https://github.com/tokio-rs/tracing/assets/141300/f8b0b1af-fe66-41d8-9a08-2ecba2d67f9e">


## Solution

This change adds the missing prefixes to the `$($k)` tokens, like they
already exist for the simple cases mentioned above.
  • Loading branch information
Turbo87 authored Feb 15, 2024
1 parent baeba47 commit 045b22e
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 40 deletions.
80 changes: 40 additions & 40 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,10 @@ macro_rules! trace {
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+)
Expand All @@ -1324,10 +1324,10 @@ macro_rules! trace {
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::TRACE, {}, $($arg)+)
Expand All @@ -1341,10 +1341,10 @@ macro_rules! trace {
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { ?$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { %$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+)
Expand All @@ -1358,10 +1358,10 @@ macro_rules! trace {
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { ?$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { %$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, {}, $($arg)+)
Expand Down Expand Up @@ -1584,10 +1584,10 @@ macro_rules! debug {
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+)
Expand All @@ -1601,10 +1601,10 @@ macro_rules! debug {
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::DEBUG, {}, $($arg)+)
Expand All @@ -1618,10 +1618,10 @@ macro_rules! debug {
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { ?$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { %$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+)
Expand All @@ -1635,10 +1635,10 @@ macro_rules! debug {
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { ?$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { %$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+)
Expand Down Expand Up @@ -1872,10 +1872,10 @@ macro_rules! info {
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+)
Expand All @@ -1889,10 +1889,10 @@ macro_rules! info {
$crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::INFO, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::INFO, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::INFO, {}, $($arg)+)
Expand All @@ -1906,10 +1906,10 @@ macro_rules! info {
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { ?$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { %$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+)
Expand All @@ -1923,10 +1923,10 @@ macro_rules! info {
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { ?$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { %$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::INFO, {}, $($arg)+)
Expand Down Expand Up @@ -2153,10 +2153,10 @@ macro_rules! warn {
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+)
Expand All @@ -2170,10 +2170,10 @@ macro_rules! warn {
$crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::WARN, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::WARN, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::WARN, {}, $($arg)+)
Expand All @@ -2187,10 +2187,10 @@ macro_rules! warn {
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { ?$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { %$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+)
Expand All @@ -2204,10 +2204,10 @@ macro_rules! warn {
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { ?$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { %$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::WARN, {}, $($arg)+)
Expand Down Expand Up @@ -2430,10 +2430,10 @@ macro_rules! error {
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+)
Expand All @@ -2447,10 +2447,10 @@ macro_rules! error {
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, { ?$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, { %$($k).+ $($field)+ })
);
(name: $name:expr, target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, target: $target, $crate::Level::ERROR, {}, $($arg)+)
Expand All @@ -2464,10 +2464,10 @@ macro_rules! error {
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { ?$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { %$($k).+ $($field)+ })
);
(target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+)
Expand All @@ -2481,10 +2481,10 @@ macro_rules! error {
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { ?$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ })
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { %$($k).+ $($field)+ })
);
(name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => (
$crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, {}, $($arg)+)
Expand Down
Loading

0 comments on commit 045b22e

Please sign in to comment.