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 and hds committed Nov 22, 2024
1 parent 444e5a4 commit 6de7661
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 @@ -1309,10 +1309,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 @@ -1326,10 +1326,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 @@ -1343,10 +1343,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 @@ -1360,10 +1360,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 @@ -1586,10 +1586,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 @@ -1603,10 +1603,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 @@ -1620,10 +1620,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 @@ -1637,10 +1637,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 @@ -1874,10 +1874,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 @@ -1891,10 +1891,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 @@ -1908,10 +1908,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 @@ -1925,10 +1925,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 @@ -2155,10 +2155,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 @@ -2172,10 +2172,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 @@ -2189,10 +2189,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 @@ -2206,10 +2206,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 @@ -2432,10 +2432,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 @@ -2449,10 +2449,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 @@ -2466,10 +2466,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 @@ -2483,10 +2483,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 6de7661

Please sign in to comment.