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

Pass paramaters into a new span in #[trace] macro #5

Closed
hawkw opened this issue Feb 8, 2019 · 1 comment
Closed

Pass paramaters into a new span in #[trace] macro #5

hawkw opened this issue Feb 8, 2019 · 1 comment
Labels
crate/attributes Related to the `tracing-attributes` crate good first issue Good for newcomers kind/feature New feature or request

Comments

@hawkw
Copy link
Member

hawkw commented Feb 8, 2019

copied from hawkw/tokio-trace-prototype#53:

As @hawkw said on #16:

For future work: it would be really cool if we could pass all the params to the function as fields here as well.
Since some parameters may not be valid span fields, we might consider adding an additional attribute (#[trace_ignore]?) to annotate those fields that should be skipped.

@hawkw hawkw added the good first issue Good for newcomers label Feb 8, 2019
@hawkw
Copy link
Member Author

hawkw commented Feb 8, 2019

We can probably just field::debug most function args, although it might still be worth having an ignore attribute for those that don't implement Debug.

@hawkw hawkw added kind/feature New feature or request crate/attributes Related to the `tracing-attributes` crate labels Feb 8, 2019
@hawkw hawkw closed this as completed in #10 Feb 9, 2019
hawkw pushed a commit that referenced this issue Feb 9, 2019
The parameters to the function are now passed as fields into `span!` so
that we can see what arguments a traced function is called with.

Before:
```
DEBUG 2019-02-08T22:51:06Z: args: fibonacci_seq: Pushing 0 fibonacci; traced_function="fibonacci_seq";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: fibonacci_seq: Pushing 1 fibonacci; traced_function="fibonacci_seq";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: fibonacci_seq: Pushing 2 fibonacci; traced_function="fibonacci_seq";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: fibonacci_seq: Pushing 3 fibonacci; traced_function="fibonacci_seq";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
DEBUG 2019-02-08T22:51:06Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci";
```

After:
```
DEBUG 2019-02-08T22:53:03Z: args: fibonacci_seq: Pushing 0 fibonacci; traced_function="fibonacci_seq"; to=5;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=0;
DEBUG 2019-02-08T22:53:03Z: args: fibonacci_seq: Pushing 1 fibonacci; traced_function="fibonacci_seq"; to=5;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=1;
DEBUG 2019-02-08T22:53:03Z: args: fibonacci_seq: Pushing 2 fibonacci; traced_function="fibonacci_seq"; to=5;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci"; n=2;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=1;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=0;
DEBUG 2019-02-08T22:53:03Z: args: fibonacci_seq: Pushing 3 fibonacci; traced_function="fibonacci_seq"; to=5;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci"; n=3;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Recursing; traced_function="nth_fibonacci"; n=2;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=1;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=0;
DEBUG 2019-02-08T22:53:03Z: args: nth_fibonacci: Base case; traced_function="nth_fibonacci"; n=1;
```

Closes #5 

Signed-off-by: Kevin Leimkuhler <kevinl@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyantio>
@hawkw hawkw added this to the tracing-macros 0.1 milestone Jul 8, 2019
hawkw added a commit that referenced this issue Jan 28, 2022
## Motivation

In my library I define a `macro_rules! concat` macro, i.e.
[`callbag::concat`](https://docs.rs/callbag/latest/callbag/macro.concat.html).

When I try to call `tracing::info!(...)`, I get error output such as
this:

<details>
<summary>error output</summary>

<!-- leave a blank line above -->
```
> RUSTFLAGS='-Z macro-backtrace' cargo +nightly clippy --features trace
    Checking callbag v0.14.0 (/home/teohhanhui/projects/teohhanhui/callbag-rs)
error[E0308]: mismatched types
  --> src/concat.rs:89:9
   |
89 |         info!("from sink: {message:?}");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `u32`

error[E0277]: the trait bound `std::sync::Arc<core::Callbag<never::Never, _>>: std::convert::From<&str>` is not satisfied
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `std::sync::Arc<core::Callbag<never::Never, _>>`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (#3)
     |   in this expansion of `$crate::event!` (#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (#2)
     |
     = help: the following implementations were found:
               <std::sync::Arc<B> as std::convert::From<std::borrow::Cow<'a, B>>>
               <std::sync::Arc<T> as std::convert::From<T>>
               <std::sync::Arc<T> as std::convert::From<std::boxed::Box<T>>>
               <std::sync::Arc<[T]> as std::convert::From<&[T]>>
             and 9 others
     = note: required because of the requirements on the impl of `std::convert::Into<std::sync::Arc<core::Callbag<never::Never, _>>>` for `&str`
note: required by a bound in `concat::concat`
    --> src/concat.rs:81:8
     |
72   | pub fn concat<
     |        ------ required by a bound in this
...
81   |     S: Into<Arc<Source<T>>> + Send + Sync,
     |        ^^^^^^^^^^^^^^^^^^^^ required by this bound in `concat::concat`

error[E0308]: mismatched types
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found struct `core::Callbag`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (#3)
     |   in this expansion of `$crate::event!` (#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (#2)
     |
     = note: expected reference `&'static str`
                   found struct `core::Callbag<never::Never, _>`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `callbag` due to 3 previous errors
```
</details>

This is because of my `concat` macro being in scope.

## Solution

This branch adds a re-export of `core::concat!` in the
`__macro_support` module, and changes all the `tracing` macros to use
that, rather than using an un-namespaced `concat!`. The re-export
ensures that everything still works even in a crate that redefines the
`core` name to something else.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw pushed a commit that referenced this issue Feb 9, 2022
Re-application of changes made in #1842 which were lost in f1cf1f1

Integration tests added for regression.

---

## Motivation

In my library I define a `macro_rules! concat` macro, i.e.
[`callbag::concat`](https://docs.rs/callbag/latest/callbag/macro.concat.html).

When I try to call `tracing::info!(...)`, I get error output such as
this:

<details>
<summary>error output</summary>

<!-- leave a blank line above -->
```
> RUSTFLAGS='-Z macro-backtrace' cargo +nightly clippy --features trace
    Checking callbag v0.14.0 (/home/teohhanhui/projects/teohhanhui/callbag-rs)
error[E0308]: mismatched types
  --> src/concat.rs:89:9
   |
89 |         info!("from sink: {message:?}");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `u32`

error[E0277]: the trait bound `std::sync::Arc<core::Callbag<never::Never, _>>: std::convert::From<&str>` is not satisfied
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `std::sync::Arc<core::Callbag<never::Never, _>>`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (#3)
     |   in this expansion of `$crate::event!` (#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (#2)
     |
     = help: the following implementations were found:
               <std::sync::Arc<B> as std::convert::From<std::borrow::Cow<'a, B>>>
               <std::sync::Arc<T> as std::convert::From<T>>
               <std::sync::Arc<T> as std::convert::From<std::boxed::Box<T>>>
               <std::sync::Arc<[T]> as std::convert::From<&[T]>>
             and 9 others
     = note: required because of the requirements on the impl of `std::convert::Into<std::sync::Arc<core::Callbag<never::Never, _>>>` for `&str`
note: required by a bound in `concat::concat`
    --> src/concat.rs:81:8
     |
72   | pub fn concat<
     |        ------ required by a bound in this
...
81   |     S: Into<Arc<Source<T>>> + Send + Sync,
     |        ^^^^^^^^^^^^^^^^^^^^ required by this bound in `concat::concat`

error[E0308]: mismatched types
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found struct `core::Callbag`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (#3)
     |   in this expansion of `$crate::event!` (#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (#2)
     |
     = note: expected reference `&'static str`
                   found struct `core::Callbag<never::Never, _>`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `callbag` due to 3 previous errors
```
</details>

This is because of my `concat` macro being in scope.

## Solution

Change all the `tracing` macros to use the re-export of `core::concat!`
in the `__macro_support` module, rather than using an un-namespaced
`concat!`. The re-export ensures that everything still works even in a
crate that redefines the `core` name to something else.
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
Re-application of changes made in tokio-rs#1842 which were lost in f1cf1f1

Integration tests added for regression.

---

## Motivation

In my library I define a `macro_rules! concat` macro, i.e.
[`callbag::concat`](https://docs.rs/callbag/latest/callbag/macro.concat.html).

When I try to call `tracing::info!(...)`, I get error output such as
this:

<details>
<summary>error output</summary>

<!-- leave a blank line above -->
```
> RUSTFLAGS='-Z macro-backtrace' cargo +nightly clippy --features trace
    Checking callbag v0.14.0 (/home/teohhanhui/projects/teohhanhui/callbag-rs)
error[E0308]: mismatched types
  --> src/concat.rs:89:9
   |
89 |         info!("from sink: {message:?}");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `u32`

error[E0277]: the trait bound `std::sync::Arc<core::Callbag<never::Never, _>>: std::convert::From<&str>` is not satisfied
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `std::sync::Arc<core::Callbag<never::Never, _>>`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (tokio-rs#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (tokio-rs#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (tokio-rs#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (tokio-rs#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (tokio-rs#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (tokio-rs#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (tokio-rs#3)
     |   in this expansion of `$crate::event!` (tokio-rs#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (tokio-rs#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (tokio-rs#2)
     |
     = help: the following implementations were found:
               <std::sync::Arc<B> as std::convert::From<std::borrow::Cow<'a, B>>>
               <std::sync::Arc<T> as std::convert::From<T>>
               <std::sync::Arc<T> as std::convert::From<std::boxed::Box<T>>>
               <std::sync::Arc<[T]> as std::convert::From<&[T]>>
             and 9 others
     = note: required because of the requirements on the impl of `std::convert::Into<std::sync::Arc<core::Callbag<never::Never, _>>>` for `&str`
note: required by a bound in `concat::concat`
    --> src/concat.rs:81:8
     |
72   | pub fn concat<
     |        ------ required by a bound in this
...
81   |     S: Into<Arc<Source<T>>> + Send + Sync,
     |        ^^^^^^^^^^^^^^^^^^^^ required by this bound in `concat::concat`

error[E0308]: mismatched types
    --> src/concat.rs:58:9
     |
56   | / macro_rules! concat {
57   | |     ($($s:expr),* $(,)?) => {
58   | |         $crate::concat(::std::vec![$($s),*].into_boxed_slice())
     | |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found struct `core::Callbag`
59   | |     };
60   | | }
     | |_- in this expansion of `concat!` (tokio-rs#5)
...
89   |           info!("from sink: {message:?}");
     |           ------------------------------- in this macro invocation (tokio-rs#1)
     |
    ::: src/utils/tracing.rs:47:1
     |
47   | / macro_rules! info {
48   | |     ($($arg:tt)+) => {
49   | |         ::cfg_if::cfg_if! {
50   | |             if #[cfg(feature = "trace")] {
51   | |                 ::tracing::info!($($arg)+)
     | |                 -------------------------- in this macro invocation (tokio-rs#2)
...    |
54   | |     };
55   | | }
     | |_- in this expansion of `info!` (tokio-rs#1)
     |
    ::: /home/teohhanhui/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/tracing-0.1.29/src/macros.rs:586:1
     |
586  |   macro_rules! event {
     |  _-
     | |_|
     | |
587  | |     (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> (
588  | |         $crate::__tracing_log!(
589  | |             target: $target,
...    |
644  |                   name: concat!(
     |  _______________________-
645  |                       "event ",
646  |                       file!(),
647  |                       ":",
648  |                       line!()
649  | |                 ),
     | |_________________- in this macro invocation (tokio-rs#5)
...
667  | /         $crate::event!(
668  |               target: $target,
669  |               $lvl,
670  |               { message = format_args!($($arg)+), $($fields)* }
671  | |         )
     | |_________- in this macro invocation (tokio-rs#4)
...
791  | |     );
792  | | }
     | | -
     | |_|
     | |_in this expansion of `$crate::event!` (tokio-rs#3)
     |   in this expansion of `$crate::event!` (tokio-rs#4)
...
1229 | / macro_rules! info {
1230 |        (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => (
1231 |           $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*)
1232 |       );
...
1398 | /         $crate::event!(
1399 | |             target: module_path!(),
1400 | |             $crate::Level::INFO,
1401 | |             {},
1402 | |             $($arg)+
1403 | |         )
     | |_________- in this macro invocation (tokio-rs#3)
1404 |       );
1405 | | }
     | |_- in this expansion of `::tracing::info!` (tokio-rs#2)
     |
     = note: expected reference `&'static str`
                   found struct `core::Callbag<never::Never, _>`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `callbag` due to 3 previous errors
```
</details>

This is because of my `concat` macro being in scope.

## Solution

Change all the `tracing` macros to use the re-export of `core::concat!`
in the `__macro_support` module, rather than using an un-namespaced
`concat!`. The re-export ensures that everything still works even in a
crate that redefines the `core` name to something else.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/attributes Related to the `tracing-attributes` crate good first issue Good for newcomers kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant