Skip to content

Commit

Permalink
fix: prefix macro calls with ::core to avoid clashing with local macr…
Browse files Browse the repository at this point in the history
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
  • Loading branch information
joshka authored and hds committed Nov 22, 2024
1 parent 40ae82f commit 0759973
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
14 changes: 11 additions & 3 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@
#[cfg(not(feature = "std"))]
extern crate alloc;

#[doc(hidden)]
pub mod __macro_support {
// Re-export the `core` functions that are used in macros. This allows
// a crate to be named `core` and avoid name clashes.
// See here: https://github.com/tokio-rs/tracing/issues/2761
pub use core::{file, line, module_path, option::Option};
}

/// Statically constructs an [`Identifier`] for the provided [`Callsite`].
///
/// This may be used in contexts such as static initializers.
Expand Down Expand Up @@ -244,9 +252,9 @@ macro_rules! metadata {
$name,
$target,
$level,
::core::option::Option::Some(file!()),
::core::option::Option::Some(line!()),
::core::option::Option::Some(module_path!()),
$crate::__macro_support::Option::Some($crate::__macro_support::file!()),
$crate::__macro_support::Option::Some($crate::__macro_support::line!()),
$crate::__macro_support::Option::Some($crate::__macro_support::module_path!()),
$crate::field::FieldSet::new($fields, $crate::identify_callsite!($callsite)),
$kind,
)
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ pub mod __macro_support {
// Re-export the `core` functions that are used in macros. This allows
// a crate to be named `core` and avoid name clashes.
// See here: https://github.com/tokio-rs/tracing/issues/2761
pub use core::{concat, format_args, iter::Iterator, option::Option};
pub use core::{concat, file, format_args, iter::Iterator, line, option::Option};

/// Callsite implementation used by macro-generated code.
///
Expand Down
12 changes: 6 additions & 6 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ macro_rules! event {
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
name: $crate::__macro_support::concat!(
"event ",
file!(),
$crate::__macro_support::file!(),
":",
line!()
$crate::__macro_support::line!()
),
kind: $crate::metadata::Kind::EVENT,
target: $target,
Expand Down Expand Up @@ -855,9 +855,9 @@ macro_rules! event {
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
name: $crate::__macro_support::concat!(
"event ",
file!(),
$crate::__macro_support::file!(),
":",
line!()
$crate::__macro_support::line!()
),
kind: $crate::metadata::Kind::EVENT,
target: $target,
Expand Down Expand Up @@ -1188,9 +1188,9 @@ macro_rules! enabled {
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
name: $crate::__macro_support::concat!(
"enabled ",
file!(),
$crate::__macro_support::file!(),
":",
line!()
$crate::__macro_support::line!()
),
kind: $kind.hint(),
target: $target,
Expand Down

0 comments on commit 0759973

Please sign in to comment.